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

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: <datasources> 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

MySQL (last edited 2009-09-20 23:41:53 by localhost)