Using c3p0 database pool

From Resin 4.0 Wiki

Revision as of 13:31, 5 September 2013 by Cowan (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Share-48.png

Using a c3p0 datasource in Resin, bound into JNDI

This configuration can go in resin.xml as a child of <cluster>, <host>, or <web-app>, or in resin-web.xml. Where you put it depends on how globally you want the pool to be shared between webapps.

You may need to add the c3p0 jar to /var/resin/lib, the main Resin shared lib directory, since the pool will be created as a shared resource upon startup.

In the top XML element, define the c3p0 namespace by adding:

 xmlns:c3p0="urn:java:com.mchange.v2.c3p0" 

Then create the pool:

 <c3p0:ComboPooledDataSource resin:Jndi="java:comp/env/jdbc/mysql">
   <driverClass>com.mysql.jdbc.Driver</driverClass>
   <jdbcUrl>jdbc:mysql://address:3306/schema</jdbcUrl>
   <user>user</user>
   <password>password</password>
   <minPoolSize>3</minPoolSize>
   <maxPoolSize>5</maxPoolSize>
 </c3p0:ComboPooledDataSource>

You can then reference the pool by the JNDI name "java:comp/env/jdbc/mysql". For eample in JPA persistence.xml:

 <jta-data-source>java:comp/env/jdbc/mysql</jta-data-source>
Personal tools
TOOLBOX
LANGUAGES