HomeDocumentation > Configuring and administering > Configuring services > Configuring datasources > Configuring a DB2 datasource

This article shows you how to configure a DB2 datasource in Apache Geronimo.

In this scenario, you will create a connection pool for a DB2 database, to connect to that database you are required to define at least two driver jar files. They include the JDBC driver itself and the respective license files. Depending on your implementation you will need different license files.

The steps described in this article are valid for deploying any other datasource when you do not have the drivers installed on the server, require multiple driver files, or both.

This article provides two alternatives to deploy the connection pool: using the Geronimo Administration Console and using the command line option.

Adding DB2 drivers to the repository

To add the DB2 drivers and license to the Geronimo repository, you are required to place the files in a particular directory structure. You will normally have two or three files to add to the repository. These files are:

  • db2jcc.jar - This is the actual DB2 Universal JDBC Driver jar file.
  • db2jcc_license_cu.jar - This is the standard DB2 Universal JDBC driver license file that allows access to the DB2 Universal database for Linux, UNIX and Windows servers.
  • db2jcc_license_cisuz.jar - This is the DB2 (DB2 ESE and DB2 Connect) JDBC Driver license for z/OS and iSeries that should be used in addition to the standard license for these servers.

These files are available in the <sqllib_home>\java directory. For additional information about the DB2 JDBC drivers and licenses, visit the DB2 Information Center available at the following URL:

http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.doc/ad/t0010264.htm

To use these files in Geronimo, rename (copy and rename) the files according to the following table. In this case, you will not use db2jcc_license_cisuz.jar because it is for Z/OS and iSeries.

Original name

Renamed

db2jcc.jar

db2jcc-9.5.jar

db2jcc_license_cu.jar

db2jcc_license_cu-9.5.jar

This means that for this particular case, DB2 v9.5 is used.

At this point, you are ready to add those files to the Geronimo repository in two ways. You can either use any graphical or command line tool to copy the files and create the necessary directories, or use the Geronimo Administration Console and add the driver and licenses to the common libraries. See the following details.

Using command line

Create the following directory structures under the <geronimo_home>\repository directory and copy the appropriate files to the respective directories.

  • com/ibm/db2/db2jcc/9.5
    and copy the db2jcc-9.5.jar file into that directory.
  • com/ibm/db2/db2jcc_license_cu/9.5
    and copy the db2jcc_license_cisuz-9.5.jar file into that directory.

Using the Geronimo Administration Console

To use the administration console, Apache Geronimo must be running. Access the Geronimo Administration Console by pointing your browser to the following URL:

http://localhost:8080/console

  1. Enter system as the user name and manager as the password and click Login.
  2. Click Services->Repository portlet.
  3. Click Browse and select the first file to install. In this case, you can install db2jcc-9.5.jar first.
  4. A set of values will be proposed by default, set the Group: to com.ibm.db2, leave the rest by default and click Install.
  5. Repeat the previous two steps for db2jcc_license_cisuz-9.5.jar.

With the drivers and license files installed, you can now create a new database connection pool.

Creating a database connection pool using the wizard from the Geronimo Administration Console

From the Geronimo Administration Console, select Database Pools and create a new pool by clicking Using the Geronimo database pool wizard.

  1. Enter the pool name DB2_ds and database type DB2(DataDirect) in the database pool wizard and then click Next. See illustration in the following figure.


  2. Select com/ibm/db2/db2jcc/9.5/jar and com.ibm/db2/db2jcc_license_cu/9.5/jar for the Driver JAR from the list by pressing Ctrl on the keyboard. Then enter the remaining connection information as shown in the following figure. For this example, the default db2admin user name and password are used and a SAMPLE database is created via the DB2 Control Center. Set localhost as the Server Name.


  3. Click Deploy. You will have DB2_ds listed in the Database Pools portlet.


Deploying a database connection pool using the command line

As an alternative to the wizard, you can create a deployment plan manually and deploy it by using the command line based deployer tool. To use this option, create a db2-plan.xml file and copy the content of the following example to the file.

db2-plan.xml deployment plan
<?xml version="1.0" encoding="UTF-8"?>
<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2">
    <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
        <dep:moduleId>
            <dep:groupId>console.dbpool</dep:groupId>
            <dep:artifactId>DB2_ds</dep:artifactId>
            <dep:version>1.0</dep:version>
            <dep:type>car</dep:type>
        </dep:moduleId>
        <dep:dependencies>
            <dep:dependency>
                <dep:groupId>com.ibm.db2</dep:groupId>
                <dep:artifactId>db2jcc</dep:artifactId>
                <dep:version>9.5</dep:version>
                <dep:type>jar</dep:type>
            </dep:dependency>
            <dep:dependency>
                <dep:groupId>com.ibm.db2</dep:groupId>
                <dep:artifactId>db2jcc_license_cu</dep:artifactId>
                <dep:version>9.5</dep:version>
                <dep:type>jar</dep:type>
            </dep:dependency>
        </dep:dependencies>
    </dep:environment>
    <resourceadapter>
        <outbound-resourceadapter>
            <connection-definition>
                <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
                <connectiondefinition-instance>
                    <name>DB2_ds</name>
                    <config-property-setting name="TraceFile"/>
                    <config-property-setting name="UserName">db2admin</config-property-setting>
                    <config-property-setting name="DatabaseName">sample</config-property-setting>
                    <config-property-setting name="Password">db2admin</config-property-setting>
                    <config-property-setting name="ServerName">localhost</config-property-setting>
                    <connectionmanager>
                        <local-transaction/>
                        <single-pool>
                            <max-size>10</max-size>
                            <min-size>0</min-size>
                            <match-one/>
                        </single-pool>
                    </connectionmanager>
                </connectiondefinition-instance>
            </connection-definition>
        </outbound-resourceadapter>
    </resourceadapter>
</connector>

In the <dep:environment> section, you can find the moduleId that identifies the resource or component being deployed; in the Administration Console the moduleId is displayed in the Component Name column on the Database Pools portlet.

Right after the moduleId is the definition of the dependencies. In this particular case, you can find three <dep:dependency> blocks pertaining to the DB2 JDBC driver and the license jar. The last "big" block in this plan is the <resourceadapter> where the connection parameters such as driver, user and password, connection URL, and so on are defined.

Deploying the datasource

To the deploy the DB2 datasource you just created, run the following command from the <geronimo_home>\bin directory.

deploy --user system --password manager deploy <dep_plan_home>\db2-plan.xml ..\repository\org\tranql\tranql-connector-db2-xa\1.4\tranql-connector-db2-xa-1.4.rar

You will receive the following message:

D:\geronimo-tomcat6-jee5-2.2\bin>deploy --user system --password manager deploy \tmp\db2-plan.xml ..\repository\org\tranql\tranql-connector-db2-xa\1.4\tranql-connector-db2-xa-1.4.rar
Using GERONIMO_BASE:   D:\geronimo-tomcat6-jee5-2.2
Using GERONIMO_HOME:   D:\geronimo-tomcat6-jee5-2.2
Using GERONIMO_TMPDIR: D:\geronimo-tomcat6-jee5-2.2\var\temp
Using JRE_HOME:        C:\Java\jdk1.6.0\jre
    Deployed console.dbpool/DB2_ds/1.0/car

Back to Top