ClassCastException - oracle.jdbc.OraclePreparedStatement

I ran into an aggravating problem, here are the facts -

I am registering a parameter of the return parameter, and for this I am using java.sql.PreparedStatement for oracle.jdbc.OraclePreparedStatement.

((OraclePreparedStatement) getStatement()) .registerReturnParameter(index, sqlType); 

This works great when I run it from Eclipse, and it works even on our development server. However, when I port it to our test server, where I find an unexpected error ...

 oracle.jdbc.driver.OraclePreparedStatementWrapper cannot be cast to oracle.jdbc.OraclePreparedStatement 

This is an incredibly strange error for me, because I am sure that OraclePreparedStatement can be assigned from getStatement (). I debugged and found this to be TRUE for all environments:

 //class oracle.jdbc.driver.OraclePreparedStatementWrapper getStatement().getClass(); 

LOCAL and DEV environments use the DataSource, which I installed in META-INF / context.xml:

 <Resource name="dataSource/dbsubm" auth="Container" type="oracle.jdbc.xa.client.OracleXADataSource" factory="org.apache.naming.factory.BeanFactory" user="*****" password="******" URL="jdbc:oracle:thin:@host:port:db" /> 

The TEST environment is different in that it has a DataSource coming from server.xml, although the configuration is exactly the same. This is for me the only difference between these environments.

What could be the problem? Why am I getting a ClassCastException using the same code, but in different environments? Using getClass (), I can say that they are all of the same type ... please help!

+4
source share
1 answer

A ClassCastException may occur if the listing crosses the boundaries of the class loader. For example, if the object class of the returned statement was loaded by a class loader other than the one loaded by OraclePreparedStatemen in your code. This may be due to the presence of two separate copies of the JDBC bank in two places, one of which is used by your Java EE container (Tomcat? WAS?), And the other by your code.

+8
source

All Articles