Tuesday, 12 February 2013

IBM DB2 type 2 Driver with weblogic


Had been facing an issue where while creating a datasource with DB2 9.7 and weblogic server 12c we were continuously facing the below error

<Error> <Console> <BEA-240003> <Administration Console encountered the following error:
java.lang.ClassNotFoundException: Cannot load driver: COM.ibm.db2.jdbc.app.DB2Driver

       at weblogic.jdbc.common.internal.DataSourceUtil.testConnection(DataSourc
eUtil.java:293)
       at com.bea.console.utils.jdbc.JDBCUtils.testConnection(JDBCUtils.java:74
6)
       at com.bea.console.actions.jdbc.datasources.createjdbcdatasource.CreateJ
DBCDataSource.testConnectionConfiguration(CreateJDBCDataSource.java:474)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)

The same was working with weblogic 8.1 and we were just trying an upgrade.

So we start the troubelshooting.

Firstly its classnotfound and not a noclassdef a big difference please Google it and you would understand.

So a classnotfound indicates classes not present apparently there are multiple ways of adding the jar file and most of them depend on how do you start the server.

Long story short we tried everything the jars were there we could see them in the logs.

So the next step. we used -verbose:class and to our surprise the class was getting loaded a couple of lines above when the server would throw the error.

See the snippet below

[Loaded COM.ibm.db2.jdbc.app.DB2Driver from file:/opt/IBM/db2/V9.7/java/db2java.zip]
[Loaded COM.ibm.db2.jdbc.app.DB2Driver$1 from file:/opt/IBM/db2/V9.7/java/db2java.zip]
[Loaded COM.ibm.db2.jdbc.app.DB2Driver$2 from file:/opt/IBM/db2/V9.7/java/db2java.zip]
[Loaded COM.ibm.db2.mri.DB2Messages from file:/opt/IBM/db2/V9.7/java/db2java.zip]
[Loaded COM.ibm.db2.mri.DB2ErrorMessages from file:/opt/IBM/db2/V9.7/java/db2java.zip]
<Error>
<Console> <BEA-240003> <Administration Console encountered the following error: java.lang.ClassNotFoundException: Cannot load driver:COM.ibm.db2.jdbc.app.DB2Driver

The above led us to belive there was something more to the issue.

We found this Doc ID 1431921.1 and we followed it however after following it the issue was the same only the classnotfound was on a different class

i.e COM.ibm.db2.jdbc.net.DB2Driver

Finally the Oracle Rep gave us a patch Bug 13870996which resolved the issue.

Turns out after all the handwork our client wants us to use Type 4 Driver hmm n ..what a waste of time but a great learning experience though.