apache > db
Apache DB Project
 
Font size:      

Accessing Databases-in-a-Jar in the Class Path

Accessing Databases-in-a-Jar in the Class Path

Once an archive containing one or more Derby databases has been created it can be placed in the class path. 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 class path, 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 class path:

  1. Set the class path 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:
    jdbc:derby:/databasePathWithinArchive
    
    

    (standard syntax)

    jdbc:derby:classpath:/databasePathWithinArchive
    
    

    (syntax with subsubprotocol)

For example:

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

When Path Is Ambiguous with Databases in 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. If this is the case, the connection attempt might fail or connect to the wrong database. Use the form of the syntax with the subsubprotocol to distinguish between the databases.

For example:

jdbc:derby:classpath:/products/boiledfood

When Path Is Ambiguous Because of Databases in Class Path

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 class path, use the following form of the connection URL:

jdbc:derby:directory:databasePathInFileSystem

For example,

jdbc:derby:directory:/products/boiledfood

Apart from the connection URL, databases in archives in the class path behave just like databases in archives accessed through the file system. However, databases in archives are read-only.


Previous Page
Next Page
Table of Contents
Index