DB2 Datasources

To use DB2 databases in Version 7 (or above?) from Cocoon you have to complete the following steps:

DB2 support for Cocoon

Here you have to install DB2, to catalog your databases in the database directory, to set the environment (usually using the command db2profile), to switch to JAVA2 support (usually using the command .../sqllib/java12/usejdbc2).

Now you should be able to connect to a DB2 database from the command line with a command like "db2 connect to mydatabase user myuserid".

Make the JDBC driver available to Cocoon

If DB2 is installed correctly, then the CLASSPATH is already extended to the DB2 directories.

Now you have to assure that your servlet server uses these classpath settings. For Tomcat you have to modify the command .../bin/setclasspath.sh (or .bat). The default of Tomcat is not to use the classpath settings at all!

# Set standard CLASSPATH

Here the original classpath has been added before tools.jar

Now add the DB2 JDBC driver to the list of preloaded classes in web.xml:

        <!-- For IBM WebSphere:
        com.ibm.servlet.classloader.Handler -->

        <!-- For Database Driver: -->

        <!-- For parent ComponentManager sample:

In this example the Oracle driver and the DB2 driver is added.

Configure a DB2 datasource

To configure a DB2 datasource you have to add a jdbc element to cocoon.xconf:

     <jdbc name="info">
      <pool-controller min="1" max="30" auto-commit="false">
       <keep-alive disable="true"/>

This example defines the datasource named "info".

You should always set keep-alive/disable to true, because the default sends an invalid SQL statement to the database with degrades performance! (You can find many errors "SELECT 1" in the db2diag.log on your database server)

If you want to have "real" transactions don't forget to set auto-commit to false!

Use the datasource from esql logicsheet

To use the datasource from a xsp serverpage with esql you use something like this:


   <!-- Select something ... -->
       select x, y,z
         from some.table t
        where x &lt; 7

   <!-- Delete something ... -->
       delete from some.table t
        where x = 4

   <!-- Commit it ... -->


If you don't want to have committed every single statement you have to state autocommit=false on every esql:connection!

Use the datasource from sql-transformer

((to be continued))

and thats all!


DB2V7 (last edited 2009-09-20 23:42:16 by localhost)