Connecting to a Derby database

To connect to a Derby database, you must perform the following steps.

  1. Start the JVM.
  2. Load the appropriate driver.
  3. Create a connection by providing a valid database connection URL.

When you use ij interactively to connect to a Derby database, you generally supply connection information on the full database connection URL. ij automatically loads the appropriate driver based on the syntax of the URL. The following example shows how to connect in this way by using the Connect command and the embedded driver:

java org.apache.derby.tools.ij
ij version 10.12
ij> connect 'jdbc:derby:sample';
ij>

If the URL entered contains Network Client information, the Connect command loads the Network Client driver:

java org.apache.derby.tools.ij
ij version 10.12
ij> connect 'jdbc:derby://localhost:1527/sample';
ij>
Note: In these and subsequent examples, the databases are created in the derby.system.home directory. For more information on the System Directory, see the Derby Developer's Guide.

ij provides alternate methods of specifying part or all of a connection URL: the ij.protocol, ij.database, and ij.connection.connectionName properties. These properties are often used when a script is being used and the database path name or the driver name is not known until runtime. The properties can also to used to shorten the amount of information that must be provided with the connection URL. The following are some examples of different ways to supply the connection information: