Connecting to a Derby database

To connect to a Derby database, you need to 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 using ij interactively to connect to a Derby database connection information is generally supplied 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 manner by using the Connect command and the embedded driver:
D:>java org.apache.derby.tools.ij
ij version 10.4
ij> connect 'jdbc:derby:sample';
ij>
If the URL entered contains Network Client information the Connect command loads the Network Client driver:
D:>java org.apache.derby.tools.ij
ij version 10.4
ij> connect 'jdbc:derby://localhost:1527/sample';
ij>
Note: In these and subsequent examples the databases were created in the derby.system.home directory. For more information on the System Directory see the Java DB Developer's Guide.

ij provides alternate methods of specifying part or all of a connection URL (e.g. the ij.protocol, ij.database, or ij.connection.connectionName properties). These properties are often used when a script is being used and the path to the database 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: