This is an old revision of the document!
Table of Contents
DB2 JDBC drivers
There are 2 types of jdbc drivers supported
- The legacy based CLI driver(Type 2)
- The new JDBC Universal driver(Type 4)
History behind the jdbc drivers
In order to understand how we came to the development of the DB2 Universal Driver, you need to understand how the JDBC specification defines the different types of drivers in the Java world.
Type 1 driver This type of driver code maps directly to a high level native API. JDBC and ODBC are similar APIs, so this type of driver is usually associated with the JDBC-ODBC bridge. This driver does not have too much context with respect to the DB2 UDB product.
Type 2 driver
A T2 driver has a native component that is part of the driver, but separate from the data access API. The native component and the Java component make up this driver. For DB2 UDB, the DB2 CLI libraries comprise the native component.
Type 3 driver
This is a Java client that communicates using a database independent protocol. Since the protocol is database independent, the advantage of this protocol falls to middleware servers that act as gateways to heterogeneous backend servers.
Type 4 driver
This driver is pure Java and implements the network protocol for a specific data source. The client connects directly to the data source.
DB2 JDBC support is provided as part of the Java enablement option for DB2 UDB clients and servers. You just need to make sure that you have the appropriate Java developer kit downloaded
Here is a comparison table
CLI legacy driver | Universal driver |
---|---|
db2java.zip | db2jcc.jar |
IN Unix: Use Type2 by placing | java/db2jcc.jar and |
java/db2java.zip in CLASSPATH | db2jcc_license_cu.jar in CLASSPATH |
Connection comparison | |
DB2 uses CLI interface | network communication. DB2 UDB uses |
CLI is the native component | distributed relational database architecture |
that communicates with the | (DRDA) to communicate to the server |
database server.This legacy based | This is a pure Java driver,run independently |
CLI driver requires common client | of what product is installed on the machine |
code | |
Driver Initialization | |
3 steps necessary to load this | Universal supports type 2 and Type4 |
driver. 1. Import java.sql* core | from a single driver.h network communication |
2. Load the JDBC driver Class.forName | uses DRDA to communicate to server and |
(COM.ibm.db2.jdbc.app.DB2Driver). | and flow requests to the database server |
3.Specify the connection URL: | The following means that a Type 2 driver is |
DriverManager getConnection | being used:jdbc:db2:database |
jdbc:db2:sample | Type4 : jdbc:db2server:port/database | | |jdbc:db2server/database |
Error Handling | |
---|---|
The legacy driver gets its error | The universal driver does not attempt to |
messages from the DB2 product and | recreate pre-existing SQL error codes |
essentially spits out the entire | has its own defined error codes |
error message back to the application | in the range +/-4200 and +/-4299 |
JCC driver Version
How to find out the JCC driver version being used in your application
% db2jcc -version red 278 % source ~db2leduc/sqllib/db2cshrc red 280 % db2jcc -version IBM DB2 JDBC Universal Driver Architecture 3.65.77 Alternatively red 281 % java com.ibm.db2.jcc.DB2Jcc -version IBM DB2 JDBC Universal Driver Architecture 3.65.77 red 283 % /cs/local/bin/java -cp /cs/local/pkg/db2/V10.1/java/db2jcc.jar com.ibm.db2.jcc.DB2Jcc -version IBM DB2 JDBC Universal Driver Architecture 3.65.77
How to display the version of the Universal Driver
red 282 % /cs/local/bin/java -cp /cs/local/pkg/db2/V10.1/java/db2jcc4.jar com.ibm.db2.jcc.DB2Jcc -version IBM Data Server Driver for JDBC and SQLJ 4.15.82