openxava / documentation / Configuration for Db2 in OpenXava 6

If you're using OpenXava 7.0 or newer look at the new instructions
Configuring your OpenXava 6.x (or older) application to go against Db2 is very simple, basically you have to install the JDBC driver for Db2 and define correctly the datasource. You don't need to touch any code of your application.
We assume you have already installed and running Db2.

Download the JDBC driver for Db2

Download the Db2 driver from here:

In the download page choose the driver for your Db2 version. It takes you to another page where you have to choose IBM Data Server Driver for JDBC and SQLJ (JCC Driver). It will ask you to register, afterwards you will be able to download the driver. You will download a file like this: db2_db2driver_for_jdbc_sqlj_v11.5.tar.gz (the version numbers may vary). Uncompress it, inside the jdbc_sqlj folder you will find Uncompress this zip too to find inside db2jcc4.jar. This last file, the .jar, is the JDBC controller we're going to use.

Create a classpath variable in Eclipse

In order you can connect to Db2 from Eclipse we're going to declare a classpath variable that points to the Db2 JDBC driver, so you can use it in any project you need easily. For that, in Eclipse go to Window > Preferences > Java > Build Path > Classpath Variables where you can add the new variable:
You can call the variable DB2_DRIVER instead of DB_DRIVER if your prefer. The path is the path of the JDBC driver, in our case the path of db2jcc4.jar we have just downloaded.

Add the DB_DRIVER variable to your Eclipse project

In the project you're going to use Db2 you have to add the variable declared above. Click with right mouse button on your project and then choose Java Build Path > Configure Build Path...:
Then select the Libraries tab:
With this we have the driver available for the development environment.

Add the JDBC driver to the production Tomcat

Adding the driver in production is much easier. Copy db2jcc4.jar to the lib folder of your Tomcat. Done.

Adjust your datasource definition

For development edit web/META-INF/context.xml of your Eclipse project, and for production edit conf/context.xml of your Tomcat to adjust the datasource to point to Db2, something like this:
<Resource name="jdbc/MyAppDS" auth="Container"
	maxTotal="100" maxIdle="20" maxWaitMillis="10000"
	username="root" password="ao49fmsk"
The differences are the driverClassName and the url. The final part of the url, myappdb in this example, is the name of your Db2 database. Obviously, instead of localhost you should put the address of the server that hosts Db2, and also put the correct username and password.

Update persistence.xml

You don't need to touch the default persistence unit of persistence.xml (in persistence/META-INF), unless you use hibernate.dialect property in which case just remove hibernate.dialect property. However, you have to modify the junit persistence unit to point to Db2.
<!-- JUnit Db2 -->
<persistence-unit name="junit">
		<property name="hibernate.connection.driver_class" value=""/>
		<property name="hibernate.connection.username" value="root"/>
		<property name="hibernate.connection.password" value="ao49fmsk"/>		
		<property name="hibernate.connection.url" value="jdbc:db2://localhost:50000/myappdb"/>
Adapt the username, password and url to your Db2 configuration.