Total Pageviews

Friday, January 08, 2010

Using the embedded database in Glassfish v2 is that simple


Using the embedded Derby database of Glassfish v2 is pretty simple.

I recently had the requirement to checkout a JEE project to a location where I don't have access to any standard database like DB2, Oracle, MySql, etc ...

Just the embedded database of Glassfish was a viable option. So I checked out the project with Maven and started a build. Before the deployment I had to configure the database to use.

I entered the Glassfish admin web interface and did the following steps:

Resources -> JDBC -> Connection Pools -> New connection pool

 Name = Name of your connection pool  
 Resource Type = javax.sql.DataSource  
 Database Vendor = Derby  

Click "Next"

DataSource Classname = org.apache.derby.jdbc.ClientDataSource (should be prefilled)

Under "Additional Properties"

 connectionAttributes => create=true (this is important)  
 User => APP (this is default)  
 DatabaseName => Name_of_your_database (this is important)  
 Password => APP (this is important)  

Click "Finish" and you are done with the connection pool. Next you will create the datasource.

Resources -> JDBC -> JDBC Resources -> New JDBC Resource

Choose the correct JNDI name which will be used by your JPA and assign the previously created pool to the resource.

Now you are finished.

The dababase will be created when you deploy your application the next time.