oracle.jdbc.OracleCallableStatement强制转换异常 [英] oracle.jdbc.OracleCallableStatement cast exception

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

问题描述

我对将CallableStatement强制转换为OracleCallableStatement有问题.它给ClassCastException像这样:

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

代码是:

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

我尝试使用spring jdbc模板,但是结果是相同的.

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

我正在使用WebLogic 10.3.2,数据源的驱动程序类为默认类.我还在项目中使用了ojdbc14.jar,启动类路径未包含它.

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.

有什么想法吗?

这些是运行时包装器类的子类:

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

推荐答案

我找到了它.那是我的lib文件夹下的ojdbc jar.我在weblogic.xml中使用如下语句:

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

prefer-webinf-classes

prefer-webinf-classes

这首先提供了使用web-inf/lib下的jar文件.因此,当在该文件夹下找到ojdbc.jar时,它仅适合我的应用程序,而不适合weblogic本身.由于weblogic在其下面以及以某种方式都有其自己的ojdbc jar,因此它只是扩展了OracleCallableStatement类以从其自己的ojdbc jar中包装它们.因为我有一个单独的ojdbc jar,所以在运行时它无法将其强制转换为我的jar的OracleCallableStatement.当我删除web-inf/lib下的jar并负责与weblogic的jdbc连接和语句部分时,它起作用了.

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.

感谢男友

这篇关于oracle.jdbc.OracleCallableStatement强制转换异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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