apache > db
Apache DB Project
 
Font size:      

Connecting to a Derby database

Connecting to a Derby database

To connect to a Derby database, you need to perform two steps:

  • Load the appropriate driver.
  • Provide a database connection URL for the database.

In ij, there are three basic ways of accomplishing these steps:

  • Full database connection URL

    ij can work with any JDBC driver. For drivers supplied by other vendors, you need to load the driver separately. For drivers supplied by Derby, you can load the driver implicitly, by specifying the full database connection URL in the connection. You do not need to load the driver explicitly in a second step.

    To connect, specify the full database connection URL in a Connect command, ij.connection.connectionName property, or ij.database property.

    The database connection URL's protocol must correspond to the driver provided by Derby (see Database connection URLs) or, if you are using another driver, to that driver.

    D:>java org.apache.derby.tools.ij
    ij version 10.0 (c) 2001,2004 IBM Corp.
    ij> connect 'jdbc:derby:toursDB';
    ij>
    
  • Protocol and short database connection URL

    For drivers supplied by Derby, specifying a protocol automatically loads the appropriate driver. You do not need to load the driver explicitly in a separate step. You specify a protocol with a property (ij.protocol or ij.protocol.protocolName) or command (Protocol).

    To connect, specify the "short form" of the database connection URL in a Connect command, ij.connection.connectionName property, or ij.database property. A short form of the database connection URL eliminates the protocol (see About Protocols).

    D:>java org.apache.derby.tools.ij
    ij version 10.0 (c) 2001,2004 IBM Corp.
    ij> protocol 'jdbc:derby:';
    ij> connect 'toursDB';
    ij>
     
    D:>java -Dij.protocol.myprotocolName=jdbc:derby:
        org.apache.derby.tools.ij
    ij version 10.0 (c) 2001,2004 IBM Corp.
    ij> connect 'toursDB' protocol myprotocolName;
    ij>
    
  • Driver and full database connection URL

    You can also load the driver explicitly with an ij property (ij.driver), a system property (jdbc.drivers), or a command (Driver).

    If you are using the driver that Derby supplies, use the driver name listed in Driver.

    The Derby drivers are implicitly loaded when a supported protocol is used. The drivers that Derby supplies are listed under Driver. Any other driver has to be explicitly loaded. You can explicitly load a driver by using an ij property (ij.driver), a system property (jdbc.drivers) or a command (Driver).

    To connect, specify the full database connection URL in a Connect command, ij.connection.connectionName property, or ij.database property.

    D:>java org.apache.derby.tools.ij
    ij version 10.0 (c) 2001,2004 IBM Corp.
    ij> driver 'sun.jdbc.odbc.JdbcOdbcDriver';
    ij> connect 'jdbc:odbc:myOdbcDataSource';
    ij>
    

Table 1, summarizes the different ways to specify the driver name and database connection URL.

Table 1. Specifying the Driver Name and database connection URL

ActionSystem Propertyij Propertyij Command
loading the driver implicitly
ij.connection.connectionName (plus full URL) ij.database (plus full URL) ij.protocolij.protocol.protocolName (plus protocol clause in Connect command)Protocol Connect (plus full URL)
loading the driver explicitlyjdbc.drivers -Dij.driver Driver
specifying the database connection URL
ij.connection.connectionName ij.database Connect

Previous Page
Next Page
Table of Contents
Index