Java Reference
In-Depth Information
7.6
Java DB/Apache Derby
As of Java SE 6, Java has included its own inbuilt database, which originated in
a small company called Cloudscape, this company subsequently being taken over
by Informix Software and the latter itself then being taken over by IBM. In 2004,
IBM donated the code to the Apache Software Foundation, which developed
the product under the name Derby . When Sun released Java SE 6, it included the
database product under the re-branded name of Java DB , although the Apache
Foundation continues to make it available as open source software under the name
Apache Derby and this (or simply Derby ) is often the name that is used in a Java
SE context. This component takes up an impressively small disc-space of 2 MB
and allows Java programmers to embed a relational database system in their
Java programs.
Also included in the product is a rather tersely and strangely named SQL script-
ing tool called ij . This can be used with either the Derby embedded JDBC driver or
with a client JDBC driver such as Derby Network Client . In either case, the associated
commands are entered into an MS-DOS command window. We'll use it with the
embedded driver.
The steps required to create, populate and manipulate a Derby database are listed
below.
1. Starting up ij
Enter the following command (into the command window):
java org.apache.derby.tools.ij
The output that is returned in response to this command should be similar to the
following:
ij version 10.9
ij> [Prompt]
The above prompt remains until the user quits in step 7.
2. Creating a Database
Use the connect command with a create attribute of true to specify the URL
of the database, using the following format for this URL:
jdbc:derby:<DbPath&Name>
Examples
connect 'jdbc:derby:Finances;create=true';
connect 'jdbc:derby:C:\\Databases\\Finances;create=true';
Search WWH ::




Custom Search