ClassCastException-oracle.jdbc.OraclePreparedStatement [英] ClassCastException - oracle.jdbc.OraclePreparedStatement

查看:115
本文介绍了ClassCastException-oracle.jdbc.OraclePreparedStatement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题越来越严重,这是事实-

I'm encountering an aggravating issue, here's the facts -

我正在注册特定的返回参数,并且这样做是将java.sql.PreparedStatement转换为oracle.jdbc.OraclePreparedStatement.

I'm registering a return parameter specific and to do so I'm casting a java.sql.PreparedStatement to oracle.jdbc.OraclePreparedStatement.

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

当我从Eclipse运行此程序时,此方法效果很好,甚至可以在我们的开发服务器上按预期运行.但是,这是我将其移至测试服务器时遇到意外错误的原因……

This works great when I run this from Eclipse and it even runs as expected on our development server. However, it's when I move it to our testing server where I hit an unexpected error...

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

对我来说这是一个非常奇怪的错误,因为我确定可以从getStatement()分配OraclePreparedStatement.我已经调试,发现这对于所有环境都是正确的:

It's incredibly strange error to me because I'm sure that OraclePreparedStatement is assignable from getStatement(). I've debugged and found that this is TRUE for all environments:

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

LOCAL和DEV环境都使用我在META-INF/context.xml中设置的数据源:

LOCAL and DEV environments both use a DataSource I've set up 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" />

TEST环境有所不同,因为即使配置完全相同,它的数据源也来自server.xml.对我来说,这是这些环境之间的唯一区别.

TEST environment differs because it has a DataSource coming from server.xml even though the configuration is exactly the same. This to me is the only difference between these environments.

可能是什么问题?为什么我使用相同的代码但在不同的环境中得到ClassCastException?使用getClass()我可以告诉他们它们都是相同的类型...请帮助!

What could be the issue? Why do I get a ClassCastException using the same code but different environments? Using getClass() I can tell that they are all the same type... please help!

推荐答案

如果强制转换跨越类加载器边界,则可能会出现ClassCastException.例如,如果返回的语句对象的类是由与在代码中加载OraclePreparedStatemen的类加载器不同的类加载器加载的.这可能是由于在两个地方有两个单独的JDBC jar副本造成的,其中一个正被Java EE容器(Tomcat?WAS?)使用,另一个正被您的代码使用.

A ClassCastException can occur if the cast crosses classloader boundaries. For example, if the returned statement object's class was loaded by a classloader different from the one that loaded OraclePreparedStatemen in your code. This can be caused by having two separate copies of the JDBC jar in two places, one of which is being used by your Java EE container (Tomcat? WAS?) and the other by your code.

这篇关于ClassCastException-oracle.jdbc.OraclePreparedStatement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆