Connection to postgreSQL

This document explains the specific aspect of connecting Cocoon to a PosgreSQL Database.
For a general explanation on database connection please refer to the official documentation.

Downloading the jdbc drivers

The jdbc drivers can be downloaded here.
Drop the pgjdbc2.jar file either in $COCOON_HOME/web-inf/lib or $TOMCAT_HOME/common/lib/.

Setting Web.xml

In the $Cocoon_Home/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 PostgreSQL:   --> 

Setting cocoon.xconf

search for: <datasources> add into this element these lines:

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

Setting sitemap.xmap

When you want to use the connection 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

PostgreSQL (last edited 2009-09-20 23:40:30 by localhost)