IBM Support

com.ibm.ws.rsadapter.jdbc.WSJdbcConnection incompatible with oracle.jdbc.OracleConnection

Troubleshooting


Problem

In some cases the following exception might appear in the logs:
java.lang.ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection incompatible with oracle.jdbc.OracleConnection at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:103)

Cause

Anytime an application calls getConnection from a data source created by WebSphere Application Server a connection object wrapper is returned.
The Application Server requires that customer applications use that wrapped connection object to perform actions like creating statements.
In this case, the Oracle JDBC driver class oracle.sql.ArrayDescriptor has a method createDescriptor, which accepts a java.sql.Connection object as a parameter, but then attempts to cast the provided connection to an oracle.jdbc.OracleConnection class.

Resolving The Problem

The solution to this error
The above createDescriptor method has been deprecated in modern Oracle JDBC drivers, and instead users who need to create an java.sql.Array object should use the oracle.jdbc.OracleConnection createOracleArray() method.
The createOracleArray method is a non-standard method that only exists on OracleConnection objects.
In order to call this method, you need to unwrap the com.ibm.ws.rsadapter.jdbc.WSJdbcConnection as a oracle.jdbc.OracleConnection and then call the createOracleArray method.
The most modern way to get an underlying connection object is to use unwrap:
Connection conn = ds.getConnection();
if (conn.isWrappedFor(oracle.jdbc.OracleConnection.class)) {
   oracle.jdbc.OracleConnection oracleConn = conn.unwrap(oracle.jdbc.OracleConnection.class);
 java.sql.Array oracleArray = oracleConn.createOracleArray("myArray", myStructObj);
}
 
More information is available on the page Migrating applications that use the WSCallHelper interface to Liberty, it discusses migration to Liberty but this method can be used in traditional WebSphere Application Server as unwrap was added to JDBC specification in version 4.0.
Notes on how this differs from prior documentation
The old way to do the same task is using WSCallHelper class, there are two possible options.
 
1. Use the jdbcPass() or jdbcCall() methods to invoke the createOracleArray method.
2. A new CallHelper class method is available called getNativeConnection. This can be used to get the native connection to call the createOracleArray method. Note that any work done that uses the native object is not seen by WebSphere Application Server, so be sure to use the wrapped object for all other operations.

References:

Below is the Javadoc page that has syntax and examples on how the WSCallHelper class can be used:
Class WSCallHelper

Link for Data access portability features showing WSCallHelper class
 

[{"Type":"MASTER","Line of Business":{"code":"LOB45","label":"Automation"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"ARM Category":[{"code":"a8m50000000CdYAAA0","label":"WebSphere Application Server traditional-All Platforms-\u003EJ2C-ConnectionPooling-JDBCDrivers-\u003EConnection Pooling-J2C-DB Connections-\u003EConnection Pooling"}],"ARM Case Number":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"8.5.5;9.0.5"}]

Document Information

Modified date:
09 January 2023

UID

swg21409335