Project

General

Profile

How to JDBC drivers » History » Version 2

Henning Blohm, 22.09.2012 15:28

1 1 Henning Blohm
h1. How to add other JDBC drivers
2
3 2 Henning Blohm
(DRAFT)
4
5 1 Henning Blohm
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*.
6
7
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.
8 2 Henning Blohm
9
The latter approach applies in particular, if you want to modify the existing samples without setting up your own *z2-base.base* clone. 
10
11
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.
12
13
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*.
14
15
Modify the persistence unit definition in *com.zfabrik.samples.hibernate-basic.domain/java/src.impl/META-INF/persistence.xml* to use 
16
17
<pre><code class="xml">
18
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
19
</code></pre> 
20
21
instead of using the Derby dialect. Also change *com.zfabrik.samples.hibernate-basic.domain/DB.properties* to say
22
23
<pre><code class="ruby">
24
ds.prop.driverClass=com.mysql.jdbc.Driver
25
ds.prop.user=<user>
26
ds.prop.password=<password>
27
ds.prop.url=jdbc:mysql://localhost:3306/<database>
28
</code></pre> 
29
30
where of course the user name, password, and specifics of the JDBC URL need to be adapted.