Connecting to IBM DB2 v.8.x using JDBC

Trying to configure JDBC for DB2 v.8.x I had an error messages that just wouldn’t go away:

java.lang.UnsatisfiedLinkError: no db2jdbc in java.library.path

The problem appeared to be configuration issues and the fact that DB2 v.8 ships with a new universal JDBC driver. There are a number of things that are different about the new driver:

  • New driver jar-file (db2jcc.jar)
  • Requirement for a license jar-file (in my case I guessed that the required license jar-file was db2jcc_license_cu.jar since it was the only one in /opt/IBM/db2/V8.x/java)
  • Change driver class name to
    com.ibm.db2.jcc.DB2Driver
  • Make sure the native library are in the library path if using the type 2 driver (JDBC against a local DB2 installation):

    export DB2PATH=/opt/IBM/db2/V8.1
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DB2PATH/lib
    

The JDBC URL syntax is the same as previously.

If you forget adding the DB2 directory to the LD_LIBRARY_PATH you’ll get an error message saying:

com.ibm.db2.jcc.b.SqlException: Failure in loading T2 native library db2jcct2