You should write the install location somewhere and set the derby.system.home
system property to this location before creating the connection. Quoting the Using Java DB in Desktop Applications article:
Connecting to the Java DB Database
...
All connection URLs have the following
form:
jdbc:derby:<dbName>[propertyList]
The dbName
portion of the URL
identifies a specific database. A
database can be in one of many
locations: in the current working
directory, on the classpath, in a JAR
file, in a specific Java DB database
home directory, or in an absolute
location on your file system. The
easiest way to manage your database
location in an embedded environment is
to set the derby.system.home
system
property. This property tells Java DB
the default home location of all
databases. By setting this property,
the Address Book demo ensures that
Java DB always finds the correct
application database. The application
database is named DefaultAddressBook
,
and it will exist within the directory
indicated by the derby.system.home
property. The connection URL for this
database would look like this:
jdbc:derby:DefaultAddressBook
...
To connect to the DefaultAddressBook
database, the demo must first set the
derby.system.home
system property.
The demo uses the .addressbook
subdirectory of the user's home
directory. Use the System class to
find out the user's home directory.
Then use the class again to set the
derby.system.home
property:
private void setDBSystemDir() {
// Decide on the db system directory: <userhome>/.addressbook/
String userHomeDir = System.getProperty("user.home", ".");
String systemDir = userHomeDir + "/.addressbook";
// Set the db system directory.
System.setProperty("derby.system.home", systemDir);
}