Project

General

Profile

Actions

How to JDBC drivers » History » Revision 2

« Previous | Revision 2/10 (diff) | Next »
Henning Blohm, 22.09.2012 15:28


How to add other JDBC drivers

(DRAFT)

There are different alternatives on how to add a JDBC driver to Z2. If you set up your own system (as in How to create your own system) we recommend to stick to the Z2 convention and put all JDBC drivers into the module com.zfabrik.db.drivers.

Another approach that should work as well is to put your drivers into your domain module (as in for example Sample-hibernate-basic), or if you have more than one, in some shared utility module that is referenced by all domain modules.

The latter approach applies in particular, if you want to modify the existing samples without setting up your own z2-base.base clone.

Let's assume we want to use the sample Sample-hibernate-basic with MySQL instead of Derby. Due to licensing issues, Z2 does not contain the MySQL JDBC driver.

If you have the sample installed and setup, go to http://dev.mysql.com/downloads/connector/j/ and download the JDBC driver for MySQL. Extract the .jar file into com.zfabrik.samples.hibernate-basic.domain/java/bin.api/lib.

Modify the persistence unit definition in com.zfabrik.samples.hibernate-basic.domain/java/src.impl/META-INF/persistence.xml to use

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

instead of using the Derby dialect. Also change com.zfabrik.samples.hibernate-basic.domain/DB.properties to say

ds.prop.driverClass=com.mysql.jdbc.Driver
ds.prop.user=<user>
ds.prop.password=<password>
ds.prop.url=jdbc:mysql://localhost:3306/<database>

where of course the user name, password, and specifics of the JDBC URL need to be adapted.

Updated by Henning Blohm over 11 years ago · 2 revisions