0

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 ?

Tarlog
  • 10,024
  • 2
  • 43
  • 67
af_khan
  • 1,030
  • 4
  • 25
  • 49
  • To which class are you trying to cast it? when it occurs? Maybe code sample? – Francisco Spaeth Oct 26 '11 at 09:21
  • OraclePreparedStatement vStmt = null; OracleResultSet vSet = null; ArrayList vFiles = new ArrayList(); try { vSqlStr = "some query here"; vStmt = (OraclePreparedStatement) aConn.prepareStatement(vSqlStr); – af_khan Oct 26 '11 at 09:26
  • also. we have updated the driver from ojdbc5-11.2.0.2.0 to ojdbc5-11.2.0.3.0 – af_khan Oct 26 '11 at 09:29
  • You cannot do this because you are probably using the data source mechanism provided by your container (Weblogic in this case) which wraps JDBC objects such as connections, statements etc. into its own wrappers which are not 'castable' into `OraclePreparedStatement`. Please describe in more detail what it is that you are trying to do and we may be able to suggest alternate ways of doing it. – ivantod Oct 26 '11 at 09:41
  • As far as can be seen from the exception you're getting a stub implementation of prepared statement from the WebLogic container and I assume the OraclePreparedStatement is somewhere inside it. Try to find in the WebLogin documentation how to retrieve the wrapped stmt. Other solution would be not to use the WebLogic Connection container. – Udi Cohen Oct 26 '11 at 09:45
  • @UdiCohen ...or an even better solution would to NOT cast into Oracle implementation specific objects. In my experience it is rarely necessary to do that as either it is possible to use standard JDBC mechanisms or the container provides a 'controlled' way of doing this kind of thing (such as `jdbcCall` and `jdbcPass` on Websphere, for example) if it really cannot be avoided. – ivantod Oct 26 '11 at 09:48
  • You are totaly right @ivantod. I wrote my comment under the assumption [Afroze](http://stackoverflow.com/users/973006/afroz) **must** do the casting. – Udi Cohen Oct 27 '11 at 17:40

2 Answers2

0

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.

Francisco Spaeth
  • 23,493
  • 7
  • 67
  • 106
0

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 ..."));
user1041892
  • 121
  • 1
  • 2