ClasscastException for OraclePreparedStatement

1.2k views Asked by At

i am getting the following exception after a Jdbc driver upgrade.

Caused by: java.lang.ClassCastException: weblogic.jdbc.rmi.SerialPreparedStatement_weblogic_jdbc_rmi_internal_PreparedStatementStub_weblogic_jdbc_rmi_internal_PreparedStatementImpl_weblogic_jdbc_wrapper_PreparedStatement_oracle_jdbc_driver_OraclePreparedStatementWrapper_921_WLStub

Current Env : Weblogic 9.2.1, JDBC ojdbc5.jar

Can some help here ?

2

There are 2 answers

0
Francisco Spaeth On

Please assign it to the interface PreparedStatement instead of specific class (OraclePreparedStatement).

PreparedStatement vStmt = null; 
OracleResultSet vSet = null; 
ArrayList<ResourceFile> vFiles = new ArrayList<ResourceFile>(); 
try { 
   vSqlStr = "some query here"; 
   vStmt = aConn.prepareStatement(vSqlStr)
} catch (Exception e) {
...

The connection.prepareStatement acts like a factory for your prepared statement. That means you are not aware, and should not, which kind of object is returned from this method invocation, but you know the interface.

0
user1041892 On

This is what I have done in Weblogic 10.3 with ojdbc6 is extract the underlying Oracle connection object from the Weblogic Connection, and then you can cast the PreparedStatement's to the Oracle implementation:

oracle.jdbc.OracleConnection oracleConn = ((weblogic.jdbc.extensions.WLConnection) ret).getVendorConnection();
OraclePreparedStatement ps = (OraclePreparedStatement) conn.prepareStatement("select * from ..."));