Weblogic - Datasource exception java.lang.ClassCastException: java.math.BigInteger

This post is to discuss about a particular Issue we often face in weblogic 12c and how to resolve the same

The Issue

While trying to create mysql Datasource in weblogic, the following exception occurs and unable Test Connection (or) Test Configuration fails.

java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long<br/>com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1058)<br/>com.mysql.jdbc.SQLError.createSQLException(SQLError.java:972)<br/>com.mysql.jdbc.SQLError.createSQLException(SQLError.java:958)<br/>com.mysql.jdbc.SQLError.createSQLException(SQLError.java:903)<br/>com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1025)<br/>com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3480)<br/>com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2444)<br/>com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2214)<br/>com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:797)<br/>com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:31)<br/>sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)<br/>sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)<br/>sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)<br/>java.lang.reflect.Constructor.newInstance(Constructor.java:423)<br/>com.mysql.jdbc.Util.handleNewInstance(Util.java:395)<br/>com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:383)<br/>com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)<br/>com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:427)<br/>com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:125)<br/>com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:95)<br/>...

weblogic mysql datasource creation issue

 

Root Cause

The Error indicates that you have some JDBC driver version issues. Weblogic 12c, by default, comes with the Version 5 of mysql JDBC Connector which has to be upgraded to the latest version

 

Solution

Just upgrade the JDBC driver in weblogic 12c installation and replace the existing JDBC driver (jar file) with the latest mysql JDBC driver (Connector J) and it would fix your problem.

In my case, it is mysql Database but this can be referred for Oracle database as well.

As of now (Dec 2018) the current stable mysql version is MYSQL 8.0.13 and the driver for mysql is also available for the same version which is also backwards compatible.

The JDBC Driver of mysql is called as ConnectorJ and you can download it from here

Once you have downloaded the TAR ball, Untar it and you will get the JAR file in a name similar to mysql-connector-java-8.0.13.jar

Place the JAR file in your ORACLE_COMMON home of weblogic and append this JAR file to the WEBLOGIC_CLASSPATH variable in $ORACLE_COMMON/common/bin/commExtEnv.sh

aksarav@middlewareinventory:/apps/oracle-weblogic/wls12213/oracle_common/common/bin$ grep -i ^WEBLOGIC_CLASSPATH commExtEnv.sh|grep -i mysql – color
WEBLOGIC_CLASSPATH="${JAVA_HOME}/lib/tools.jar${CLASSPATHSEP}${PROFILE_CLASSPATH}${CLASSPATHSEP}${ANT_CONTRIB}/ant-contrib-1.0b3.jar${CLASSPATHSEP}${CAM_NODEMANAGER_JAR_PATH}:${MW_HOME}/oracle_common/modules/mysql-connector-java-8.0.13.jar"

 

To know how to find your ORACLE_HOME refer this article

What is ORACLE_HOME,MW_HOME,WL_HOME in Weblogic 12c

To know how to upgrade the JDBC Driver in weblogic refer this article

 

 

Hope this helps

Thanks,
Sarav AK

Follow me on Linkedin My Profile
Follow DevopsJunction onFacebook orTwitter
For more practical videos and tutorials. Subscribe to our channel

Buy Me a Coffee at ko-fi.com

Signup for Exclusive "Subscriber-only" Content

Loading