cocoon-database-sample

Before you start

Before you can see the sample in action make sure you have:

  1. Declared the mysql dependency in the pom (it is put to optional by default).
  2. Created a test db "c3" or updated the properties file to point a an existing one in
    cocoon-databases-sample/src/main/resources/META-INF/cocoon/properties/cocoon-databases.properties
  3. Created a test user:password "c3":"c3" (and give him/her rights for the db) or updated the properties file to point an existing one in
    cocoon-databases-sample/src/main/resources/META-INF/cocoon/properties/cocoon-databases.properties
  4. Run the sql script c3_export.sql to import the basic structure and some sample data.

SQL Transformer

Simple example using the SQL transformer to connect to the c3 database.

In
cocoon-databases-sample/src/main/resources/META-INF/cocoon/spring/cocoon-databases-context.xml
we define the database resources. You can add as many as you want. You then call them as always in the sitemap with
<map:transform type="sql">
  <map:parameter name="use-connection" value="dataSource" /> 
</map:transform>
where dataSource is our predefiened connection.

Same as above to connect to the c3 database but configured in the sitemap.

You can still pass parameter for the connection in case you do not want to use the use-connection like:
<map:transform type="sql">
   <map:parameter name="dburl" value="{global:jdbc.url}" />
   <map:parameter name="username" value="{global:jdbc.username}"/>
   <map:parameter name="password" value="{global:jdbc.password}"/>
</map:transform>