Thursday, 17 September 2015

Connect to Apache Derby (Java DB) via JDBC

Table of content:
    1. Downloading Derby JDBC driver library
    2. Loading Derby JDBC drivers
    3. Derby JDBC database connection URL for embedded driver
    4. Derby JDBC database connection URL for network client driver
    5. Making Derby JDBC connection examples
Apache Derby is a lightweight, portable database engine written purely in Java. Java DB is a just an Oracle’s distribution of Derby in their JDK. This article presents the steps to quickly get started with Derby, from downloading its JDBC driver to write code for making connections.

1.    Downloading Derby JDBC driver library

Download the latest version of Derby here (as of this writing, the latest release is 10.9.1.0). The distribution includes the following pieces of software component:
Component
Jar files
Embedded database engine and JDBC driver
derby.jar
Network client JDBC driver
derbyclient.jar
Network server
derbynet.jar, derbyrun.jar
Command line tools
derbytools.jar
Localization messages
derbyLocale_xx_YY.jar
If you are using JDK 1.7, then Derby is already included in JDK installation under the name Java DB in JDK_HOME\db directory. The jar files are located in JDK_HOME\db\lib directory. In both case, you have to place appropriate jar file to the classpath:
    • derby.jar: for embedded driver.
    • derbyclient.jar: for network client driver.


2.    Loading Derby JDBC drivers

Derby differentiates two types of JDBC driver:
Type of driver
JDBC Driver Class Name
Embedded driver
org.apache.derby.jdbc.EmbeddedDriver
Network client driver
org.apache.derby.jdbc.ClientDriver
So if you are planning to use everything of Derby in one machine, go with the embedded driver. Or if the JDBC client connects to Derby server on a remote machine, go with the network client driver.

No comments:

Post a Comment