Wednesday, August 10, 2011

Using Apache Derby with JDeveloper to develop ADF applications - Part 1

Apache Derby is an open source relational database written completely in Java. It has a small footprint (just 2.6 MB) and it is based on Java, JDBC and SQL standards. You can get more information about Derby at

Derby database can be used in Embedded as well as Client Server modes. In Embedded mode you can embed Derby within any Java based solution (so there is no overhead of maintaining the database server). Client server mode is the more familiar mode which you might have used with other databases such as Oracle.

So why would you want to use Derby to develop ADF applications? There could be many reasons but following are some reasons which appealed to me

1) For learning ADF using your OWN desktop! - Try installing Oracle database (or for that matter Oracle XE database) + JDeveloper on your desktop, which has paltry RAM. You will be lucky if your Hello World page runs. Derby’s small footprint comes in to rescue here as the database resources consumed by your system are very less.

2) If you want to develop Desktop applications using ADF Faces technology, the same reason mentioned above applies. Now why would you want to develop desktop application using ADF Faces? That is the subject of a different article which we will publish some day.

Following are the steps to use Derby in JDeveloper

1) Download the latest official release of derby from the derby home page. During the time of writing this article the latest release was

2) Extract the contents of the downloaded file to a suitable directory. The “lib” folder contains two important JAR files which will be used to connect to the derby database.

a. derby.jar – This is the Embedded driver which contains the JDBC class “org.apache.derby.jdbc.EmbeddedDriver”

b. derbyclient.jar - This is the Client Server driver which contains the JDBC class “org.apache.derby.jdbc.ClientDriver”

3) Now open JDeveloper (I am using version and create a new Application. Choose ‘Fusion Web Application (ADF)’ from the list of choices. Enter application details as show in the following screenshot.

4) For rest of the steps accept default entries and click ‘Finish’. This will create your ADF Faces project.

5) Now click on the Step 2 ‘Connect to a Database’ on the Quick Start checklist and then click ‘Create a Database Connection’


Go the database navigator, right click on the application and select ‘New Connection’

This opens the create database connection dialog box. Enter following details

a) Connection Name – Provide a suitable name to your Database connection lets say DerbyADFDB

b) Connection Type – Choose ‘Generic JDBC’

c) Username – app

d) Password - app

e) Save Password – Checked

f) In the Generic JDBC Settings ‘New’ for the Driver Class.

i. Driver class - org.apache.derby.jdbc.ClientDriver

ii. Library click ‘Browse’ and Create a new Library for Apache Derby drivers as in screenshots below.

Click ‘New’ to create a new library. Click ‘Add Entry’, browse to the path where the Derby JAR files discussed in step 2 are available and add them to the Class Path

Click ‘Ok’ and get back to the ‘Create Database Connection’ screen.

g) Repeat the above to create the Embedded driver class ‘org.apache.derby.jdbc.EmbeddedDriver’

h) JDBC URL - If you are using the Client Driver enter


If you are using the Embedded Driver enter


Over here

i. ‘DerbyADFDB’ is the name of the database

ii. ‘create=true’ tells the driver to create the database if it is not already created.

iii. //localhost:1527/ is the URL path where the derby server is listening for client requests. This is required when you are using the Client Driver.

6) In case of Client Driver to test the connection, you will have to start the server service. Go to Derby home directory > bin > Run the batch file ‘startNetworkServer.bat’

7) Then click on ‘Test Connection’. The connection should be successful.

And the DerbyADFDB database (i.e. database folder and files) would have got created in the /bin folder

8) If you want to use Embedded Driver following would be the settings.

(Note: While using Embedded Driver you might face issue running your project in JDeveloper as Embedded Driver only allows one connection to the database. So if your design needs you to use Embedded driver, my suggestion is for development in JDeveloper use Client Driver and switch to Embedded driver when you actually deploy your application to the target application server).

9) Click ‘Ok’ and your Database connection in JDeveloper is successfully created. You can now use Database navigator within JDeveloper to create/update database objects.

10) The new database connection that you created can now be used within your Model project to create ADF BC components.

No comments:

Post a Comment