728x90

Installation


DB2 JDBC support is provided as part of the Java enablement option for DB2 UDB clients and servers. No special installation is required; you just need to make sure that you have the appropriate Java developer kit downloaded for your particular platform. The DB2 Information Center contains detailed information on how to set up your environment for Java on both UNIX and Windows. (See Resources.)

Table 1. Installation comparison
CLI legacy driverUniversal driver
The physical representation of the legacy-based CLI driver is the db2java.zip file.The physical representation of the universal JDBC driver is the db2jcc.jar file.
In the UNIX environment, you can use the Type 2 legacy-based driver by making sure that you have sqllib/java/db2java.zip in your CLASSPATH. The same applies to Windows.In the UNIX environment, you can use the Type 4 universal driver by making sure you have both sqllib/java/db2jcc.jar and db2jcc_license_cu.jar in the CLASSPATH. Windows instructions are the same.
The support that is enabled for this driver is JDBC 2.0 and some JDBC 3.0.Support includes most implementations of JDBC 3.0, as long as you have JDK1.4.x installed as part of your Java package.


Connection

The difference between the two JDBC drivers is shown in the way that they make their connections. The essential function of JDBC is to connect to the database and send SQL statements to the server. It has the capability of processing a result set and sending it to the requestor.

Table 2. Connection comparison
CLI legacy driverUniversal driver
The connection to the database occurs through a native database interface; in this case, DB2 uses CLI. The JDBC layer sits on top of CLI, and CLI is the native component that communicates with the database server.Everything is pure Java, and the way it communicates with the database server is though network communication. DB2 UDB uses distributed relational database architecture (DRDA) to communicate to the server and flow requests to the database server.
Since the legacy-based CLI driver requires common client code, it also requires a DLL/shared object. The DB2 product must be installed in order to use this driver.This is a pure Java driver and so can run independently of what product is installed on the machine where it runs. That is, it can be considered as a separate entity on its own and independent of the DB2 product it is shipped with.


Driver initialization

The way you actually write the code to load the driver changes depends on which driver you want to use. There are two ways the connection can be established. As with all JDBC resources, invoke the connections close method when you are done with the connection.

Table 3. Driver initialization comparison
CLI legacy driverUniversal driver
There are three essential steps needed to load and make this connection:
  1. Import the JDBC core classes (for example,import java.sql*).
  2. Load the JDBC driver Class.forName (COM.ibm.db2.jdbc.app.DB2Driver).
  3. Specify the connection URL:DriverManager getConnection jdbc:db2:coffebk.
The universal driver supports both Type 2 and Type 4 connectivity from a single driver.h network communication. DB2 UDB uses distributed relational database architecture (DRDA) to communicate to the server and flow requests to the database server.

The way you tell whether you are using the Type 2 or Type 4 driver is from the form of the connection. The following indicates that a Type 2 or Type 4 driver is being used:

jdbc:db2//server:port/database 
jdbc:db2//server/database 

The following means that a Type 2 driver is being used:
jdbc:db2:database

You have the ability to use the Type 3 driver if you want, in which case the syntax for the driver initialization will be:COM.ibm.db2.jdbc.net.DB2Driver.You can toggle between the two drivers' material layers with the connection level that you use.


Features

The introduction of DB2 UDB, Version 8 has enabled Java development to become more versatile and programming independent. Most development efforts are now focused on adding new features, improved memory management, and stability in the new JDBC Universal Driver.

Table 4. Features comparison
CLI legacy driverUniversal driver
This driver needs to specifically have the DB2 UDB product installed, as it relies on the native code of the product.This driver can be considered an independent product. It does not require the product to be installed, and it can be shipped with the many DB2 platforms that the product ships with.
Legacy driver versions are in line with DB2 UDB fix packs and, as such, are only shipped when a fix pack is released.The shipping of the JCC driver is independent of the fix pack. JCC drivers have their own versions and are shipped as needed by the release for any DB2 product. For example, DB2 V8.20 fp9 may ship with JCC driver version 2.3.9, whereas DB2 V8.20 OS/390 PTF UQ72081 may ship with JCC driver version 2.3.11.


Error handling

The two types of JDBC drivers handle errors in very different ways. The development of the error messages are still ongoing and in developing phases for the new driver, but newer versions hold more improved error handling for the universal driver. When you look at a typical JDBC exception, it will consist of an SQLErrorCode, SQLState, and SQLMessage.

Table 5. Error handling comparison
CLI legacy driverUniversal driver
The legacy driver gets its error messages from the DB2 product and essentially spits out the entire error message back to the application.The universal driver does not attempt to recreate pre-existing SQL error codes that were issued by the legacy CLI/JDBC products. The universal driver has its own defined error codes in the range +/-4200 and +/-4299.
Undefined error codes issued by the universal driver are given the error code of -99999.
If an error comes from a DB2 subsystem like DB2 server of underlying DB2 client library, then JCC will just echo that error message.


Transaction management

A transaction is a set of one or more statements that are executed together as a unit of work (UOW). Transactions are used to make sure that all transactions that are part of a UOW are executed or that none of them are executed at all. With respect to the drivers, J2EE specifies simple transaction management.

Table 6. Transaction management
CLI legacy driverUniversal driver
XA support has been enabled for this driver for a very long time.As of V8.20, XA support was enabled for the Type 4 JDBC universal driver.



http://www.ibm.com/developerworks/data/library/techarticle/dm-0512kokkat/

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

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

728x90

+ Recent posts