Description: Once an archive containing one or more Derby databases has been created it can be placed in the classpath. This allows access to a database from within an application without the application's knowing the path of the archive.
Keywords: Accessing read-only databases from classpath, Read-only databases, putting in classpath

# Accessing databases within a jar file using the classpath

Once an archive containing one or more Derby databases has been created it can be placed in the classpath. This allows access to a database from within an application without the application's knowing the path of the archive.

When jar or zip files are part of the classpath, you do not have to specify the jar subsubprotocol to connect to them.

To access a database in a zip or jar file in the classpath:

1. Set the classpath to include the jar or zip file before starting up Derby:

       CLASSPATH="C:\dbs.jar;%CLASSPATH%"

2. Connect to a database within the jar or zip file with one of the following connection URLs:

       Standard syntax:
       jdbc:derby:/databasePathWithinArchive

       Syntax with subsubprotocol:
       jdbc:derby:classpath:/databasePathWithinArchive

For example:

    jdbc:derby:/products/boiledfood
    jdbc:derby:classpath:/products/boiledfood

- Connecting to databases with ambiguous paths to databases in the file system
  Use the basic connection URL syntax only if the database path specified does not also point to a Derby database in the file system.
- Connecting to databases when the path is ambiguous because of databases in the classpath
  To connect to a database in the file system when the connection URL that you would use would be ambiguous with a database in the classpath, use the following form of the connection URL.

Parent topic: Creating Derby databases for read-only use