Accessing databases from the classpath

In most cases, you access databases from the file system. However, it is also possible to access databases from the classpath. The databases can be archived into a jar or zip file or left as is.

All such databases are read-only.

To access an unarchived database from the classpath, specify the name of the database relative to the directory in the classpath. You can use the classpath subprotocol if such a database is ambiguous within the directory system. See Embedded Derby JDBC database connection URL for more information.

For example, for a database called sample in C:\derby\demo\databases, you can put the C:\derby\demo\databases directory in the classpath and access sample like this:

jdbc:derby:/sample

The forward slash is required before sample to indicate that it is relative to C:\derby\demo\databases directory.

If only C:\derby were in the class path, you could access sample (read-only) like this:

jdbc:derby:/demo/databases/sample
Related concepts
Accessing databases from a jar or zip file