Search code examples
javaoraclejdbcweblogicclasscastexception

oracle.jdbc.OracleCallableStatement cast exception


I have a problem about casting a CallableStatement to OracleCallableStatement. It gives ClassCastException like this:

java.lang.ClassCastException:
    oracle.jdbc.driver.OracleCallableStatementWrapper cannot be cast to
    oracle.jdbc.driver.OracleCallableStatement

And the code is:

Connection conn = qdbDataSource.getConnection();
PreparedStatement pstmt = null;
Connection conn2 = ((WLConnection)conn).getVendorConnection();
try {
    CallableStatement cs = conn2.prepareCall("{ ?=call asr.bsc(?,?,?,?,?,?,?)}");
    OracleCallableStatement ocs = (OracleCallableStatement)cs;
// (...)
}

I tried to use spring jdbc template, but result was the same.

I am using WebLogic 10.3.2 and the driver class of the datasource is default one. I'm also using the ojdbc14.jar in my project, the startup classpath does not include it.

Any ideas?

EDIT: These are the subclasses of the runtime wrapper class:

weblogic.jdbc.wrapper.CallableStatement_oracle_jdbc_driver_OracleCallableStatementWrapper class
weblogic.jdbc.wrapper.CallableStatement class
weblogic.jdbc.wrapper.PreparedStatement class
weblogic.jdbc.wrapper.Statement class
weblogic.jdbc.wrapper.JDBCWrapperImpl class
weblogic.utils.wrapper.WrapperImpl class java.lang.Object

Solution

  • I found it. It was the ojdbc jar under my lib folder. I am using a statement in weblogic.xml like:

    prefer-webinf-classes

    And this provides to use the jar files under web-inf/lib in the first place. So when it finds an ojdbc.jar under that folder, it just fits for my application but not for weblogic itself. Because weblogic has its own ojdbc jar under it and somehow, it just extends the OracleCallableStatement class to Wrap them from its own ojdbc jar. Because I have a separate ojdbc jar, at runtime, it could not cast it to my jar's OracleCallableStatement. When I removed the jar under web-inf/lib and gave the responsibility about jdbc connections and statements parts to weblogic, it worked.

    Thanks fellas