To connect to a Derby database, you need to perform the following steps:
D:>java org.apache.derby.tools.ij
ij version 10.3
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.3
ij> connect 'jdbc:derby://localhost:1527/sample';
ij>
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:
C:\>java -Dij.database=jdbc:derby:myTours;create=true
org.apache.derby.tools.ij
%DERBY_HOME%\demo\programs\toursdb\ToursDB_schema.sql
ij version 10.3
CONNECTION0* - jdbc:derby:myTours
* = current connection
ij> -- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
...output removed...
ij> CREATE TRIGGER TRIG2 AFTER DELETE ON FLIGHTS FOR EACH STATEMENT MODE DB2SQL
INSERT INTO FLIGHTS_HISTORY (STATUS) VALUES ('INSERTED FROM TRIG2');
0 rows inserted/updated/deleted
ij>
A default URL protocol and subprotocol can be specified by setting the property ij.protocol or using the ij Protocol command. This allows a connection to be made by specifying only the database name. This "short form" of the database connection URL defaults the protocol (For more information, see About Protocols).
This example uses the ij Protocol command and a "short form" connection URL:
D:>java org.apache.derby.tools.ij
ij version 10.3
ij> protocol 'jdbc:derby:';
ij> connect 'sample';
ij>
If you are using the drivers supplied by Derby, you can specify the driver names listed in JDBC drivers overview. However, the Derby drivers are implicitly loaded when a supported protocol is used so specifying them is probably redundant. Specifying a driver is required when ij is used with other JDBC drivers to connect to non-Derby databases. To use drivers supplied by other vendors explicitly specify the driver one of three ways
D:>java org.apache.derby.tools.ij
ij version 10.3
ij> driver 'sun.jdbc.odbc.JdbcOdbcDriver';
ij> connect 'jdbc:odbc:myOdbcDataSource';
ij>