Connection to MySQL

This document explains the specific aspects of connecting Cocoon to a MySQL Database.

For a general explanation on database connections please refer to the official Cocoon documentation .

Installing the JDBC drivers

  • The JDBC drivers can be downloaded from the website. (They are an update of the popular 'Mark Matthews' driver. (See later)
  • Expand the zip or tar file and locate the jar file mysql-connector-java-2.0.14-bin.jar (if you're using the 'Mark Matthews' driver, the jar file is called something like mm.mysql-2.0.14-bin.jar)

  • Copy this file into either $COCOON_LIB/WEB-INF/lib (default ./build/webapp/WEB-INF/lib) or $TOMCAT_HOME/common/lib/

Setting the web.xml configuration

In the $COCOON_LIB/WEB-INF/ directory you will find the web.xml file. Open it and look for this rows

 For IBM WebSphere: ..-->

here you have to add the following line:

<!-- For MySQL Driver: -->
        <!-- or use if you have the older 'Mark Matthews' driver-->

Setting the cocoon.xconf configuration

Search for:
add into this element these lines:

  <jdbc name="YourPoolName">
    <pool-controller min="5" max="10"/>

The ?autoReconnect=true tip is cribbed from the Tomcat JNDI datasource HOWTO to get around the fact that MySQL by default drops connections that have been idle for 8 hours

Setting the sitemap.xmap configuration

When you want to use the connection with the SQLTransformer you just call the JDBC name inside the pipeline in this way:

<map:match pattern="sqlquery">
  <map:generate src="sql/sqlquery.xml"/>
  <map:transform type="sql">
    <map:parameter name="use-connection" value="YourPoolName"/>
  <map:transform type="xslt" src="../stylesheets/transformation.xslt"/>
  <map:serialize type="svg2jpeg"/>

Obviously you have to adapt this sample to fill your need.


Comments from the readers

Attention: you need to have (mysql jdbc driver, saxon , jdk) working together; I'm working with JDK1.5, Saxon8, Mysql JDBC 3.06-ga

  • No labels