How to install IBM's DB2 JDBC drivers into the standard Java path ================================================================== download/get the IBM DB2 jdbc driver package. At the time of testing, I got db2_jdbc_t4_fp13.zip from www.ibm.com. verify content of the file: jar -tf db2_jdbc_t4_fp13.zip fm@DDM1307811:~> /usr/java/jdk1.5.0_09/bin/jar tf db2_jdbc_t4_fp13.zip db2_jdbc_t4_fp13/ db2_jdbc_t4_fp13/db2jcc.jar db2_jdbc_t4_fp13/db2jcc_javax.jar db2_jdbc_t4_fp13/db2jcc_license_cu.jar db2_jdbc_t4_fp13/sqlj.zip Either add the directory containing db2_jdbc_t4_fp13.zip to the classpath or: copy the extracted db2_jdbc_t4_fp13/db2jcc.jar and db2_jdbc_t4_fp13/db2jcc_license_cu.jar to $JAVA_HOME/jre/lib/ext (i.e. /usr/java1.2/jre/lib/ext) DDM1307811:/home/fm # cp db2jcc.jar /usr/java/jdk1.5.0_09/jre/lib/ext/ DDM1307811:/home/fm/db2_jdbc_t4_fp13 # ls -l /usr/java/jdk1.5.0_09/jre/lib/ext/ total 11424 drwxr-xr-x 2 root root 4096 2006-12-20 13:38 . drwxr-xr-x 16 root root 4096 2006-10-23 12:58 .. -rw-r--r-- 1 root root 1209104 2006-12-20 13:37 db2jcc.jar -rw-r--r-- 1 root root 1013 2006-12-20 13:37 db2jcc_license_cu.jar -rw-r--r-- 1 root root 8176 2006-10-12 20:45 dnsns.jar -rw-r--r-- 1 root root 802388 2006-10-23 12:58 localedata.jar -r--r--r-- 1 root root 158417 2006-10-12 20:26 sunjce_provider.jar -r--r--r-- 1 root root 175811 2006-10-12 20:26 sunpkcs11.jar verify jdbc connection to database: vi JdbcTest.java //JdbcTest.java import java.sql.Connection ; import java.sql.DriverManager ; import java.sql.ResultSet ; import java.sql.Statement ; import java.sql.SQLException; class JdbcTest { public static void main (String args[]) { try { // use the JDBCtype 4 driver Class.forName("com.ibm.db2.jcc.DB2Driver"); } catch (ClassNotFoundException e) { System.err.println (e) ; System.exit (-1) ; } try { Connection connection = DriverManager.getConnection( // open connection to database // "jdbc:db2://destinationhost:port/dbname", "dbuser", "dbpassword" // the DB2 internal data catalog is in a database called "toolsdb" "jdbc:db2://localhost:50000/toolsdb", "fm", "test" ); // build query, here we use table "SYSDBAUTH" in schema "SYSIBM" String query = "SELECT * From SYSIBM.SYSDBAUTH" ; // execute query Statement statement = connection.createStatement () ; ResultSet rs = statement.executeQuery (query) ; System.out.println ("Query:") ; while ( rs.next () ) // display content from column "GRANTEE" System.out.println (rs.getString ("GRANTEE")) ; connection.close () ; } catch (java.sql.SQLException e) { System.err.println (e) ; System.exit (-1) ; } } } Example Output: C:\>"Program Files\Java\jdk1.6.0\Java\bin\java.exe" JdbcTest Query: FM PUBLIC Remarks: - By default, IBM's DB2 uses the Operating System for user authentication and no internal password management exists. OS users are added to the database and granted DB rights. By default, local users that are logged in on the DB server itself are already authenticated to the OS and if given DB rights, no additional authentication is used. IBM's default network port (9.1 on Windows) is tcp 50000. Per default, client connection password is encrypted, data is in clear. - IBM in its infinite wisdom seems to have stopped providing a small JDBC driver package and only distributes huge DB2 client install package. After spending all the time preparing und installing, the JDBC driver can be found in /sqllib/java, which in turn is a symlink to something like db2/V9.7/java. There are the db2jcc*.jar files. - java.lang.UnsupportedClassVersionError: ~ > java JdbcTest The java class could not be loaded. java.lang.UnsupportedClassVersionError: (JdbcTest) bad major version at offset=6 This error occurs because the IBM DB2 driver was compiled against the latest Java version 1.6. Install Java 1.6 SDK and call the java 1.6 binary or downgrade to a DB2 jdbc driver compiled against a lower version of java. Literature: http://publib.boulder.ibm.com/infocenter/db2luw/v8/topic/com.ibm.db2.udb.doc/ad/c0007120.htm http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.apdv.java.doc/doc/cjvintro.htm http://www-306.ibm.com/software/data/db2/udb/support/manualsv9.html