Manually configuring a DB2 DataSource with type 2 connectivity through CICS using the jdbc-4.0 or jdbc-4.1 feature

A CICS® Liberty JVM server can be configured to use a JDBC DataSource with type 2 connectivity through CICS to access DB2® databases from Java™ applications.

Before you begin

Important: APAR PI77502 is required. Without this APAR, you might get unpredictable results.

You should configure your CICS region to connect to DB2. For more information, see Defining the CICS DB2 connection.

About this task

This task explains how to define the elements that are required in server.xml to enable JDBC type 2 driver connectivity to a local DB2 database.

Procedure

  1. Add the jdbc-4.1 or jdbc-4.0 feature to the server.xml file.

    Use the jdbc-4.0 feature if you use Java EE 6, or jdbc-4.1 if you use Java EE 7.

    <featureManager>
        <feature>jdbc-4.1</feature>
    </featureManager>
  2. Add a library element to the server.xml file to specify the location on zFS of the JDBC driver.
    <library id="defaultCICSDb2Library">
        <fileset dir="/usr/lpp/db2v11/jdbc/classes" includes="db2jcc4.jar db2jcc_license_cisuz.jar"/>
        <fileset dir="/usr/lpp/db2v11/jdbc/lib" includes="libdb2jcct2zos4_64.so"/>
    </library>
  3. To access DB2 through a DataSource definition, a dataSource element is required. The jndiName attribute is required to define the JNDI name that is referenced by your application.
    You can set attributes for the dataSource by using a properties.db2.jcc element. The following example shows how to do this:
    <dataSource id="defaultCICSDataSource" jndiName="jdbc/defaultCICSDataSource" transactional="false">
        <jdbcDriver libraryRef="defaultCICSDb2Library"/>    
        <properties.db2.jcc driverType="2"/>    
        <connectionManager agedTimeout="0"/>
    </dataSource>

    transactional="false" is required to allow CICS to manage the transactions.

    driverType="2" is required to use the type 2 connectivity to DB2.

    agedTimeout="0" is required to disable Liberty connection pooling. Liberty connection pooling is not required as the DB2CONN resource provides DB2 connection pooling.

Results

The Liberty JVM server is configured to allow access to DB2 databases by using JDBC type 2 connectivity through a CICS DB2CONN resource.