oracle.jdbc.OracleCallableStatement 转换异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11096036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
oracle.jdbc.OracleCallableStatement cast exception
提问by Neron
I have a problem about casting a CallableStatement
to OracleCallableStatement
. It gives ClassCastException
like this:
我有一个关于铸造的问题CallableStatement
来OracleCallableStatement
。它给出了ClassCastException
这样的:
java.lang.ClassCastException:
oracle.jdbc.driver.OracleCallableStatementWrapper cannot be cast to
oracle.jdbc.driver.OracleCallableStatement
And the code is:
代码是:
Connection conn = qdbDataSource.getConnection();
PreparedStatement pstmt = null;
Connection conn2 = ((WLConnection)conn).getVendorConnection();
try {
CallableStatement cs = conn2.prepareCall("{ ?=call asr.bsc(?,?,?,?,?,?,?)}");
OracleCallableStatement ocs = (OracleCallableStatement)cs;
// (...)
}
I tried to use spring jdbc template, but result was the same.
我尝试使用 spring jdbc 模板,但结果是一样的。
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.
我使用的是 WebLogic 10.3.2,数据源的驱动程序类是默认的。我也在ojdbc14.jar
我的项目中使用了,启动类路径不包括它。
Any ideas?
有任何想法吗?
EDIT: 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
回答by li-on
Cast result of getVendorConnection() to OracleConnection, than use OracleCallableStatement instead of CallableStatement,
将 getVendorConnection() 的结果转换为 OracleConnection,而不是使用 OracleCallableStatement 而不是 CallableStatement,
oracle.jdbc.OracleConnection conn2 = (oracle.jdbc.OracleConnection)(((WLConnection)conn).getVendorConnection());
回答by Simon Dorociak
java.lang.ClassCastException: oracle.jdbc.driver.OracleCallableStatementWrapper cannot be cast to oracle.jdbc.driver.OracleCallableStatement
java.lang.ClassCastException: oracle.jdbc.driver.OracleCallableStatementWrapper 不能转换为 oracle.jdbc.driver.OracleCallableStatement
So i work few weeks ago with OracleCallableStatement
and i solved it with import ojdbc6.jar
.
So you just add to your project this file and it offers directly OracleCallableStatement
,OraclePreparedStatement
etc..
所以我几周前工作OracleCallableStatement
,我用 import 解决了它ojdbc6.jar
。
所以你只需将这个文件添加到你的项目中,它就会直接提供OracleCallableStatement
,OraclePreparedStatement
等等。
All what you need is import oracle.jdbc.OracleCallableStatement;
and it will works.
您所需要的就是import oracle.jdbc.OracleCallableStatement;
它,它会起作用。
Connection con = null;
OracleCallableStatement cs = null;
try {
con = OracleDAOFactory.getOracleDatabaseConnection();
cs = (OracleCallableStatement) con.prepareCall(SOME_PROCEDURE);
...
}
Have look at this.
看看这个。
回答by Neron
I found it. It was the ojdbc jar under my lib folder. I am using a statement in weblogic.xml like:
我找到了。它是我的 lib 文件夹下的 ojdbc jar。我在 weblogic.xml 中使用了一条语句,例如:
prefer-webinf-classes
首选 webinf 类
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.
这首先提供了使用 web-inf/lib 下的 jar 文件。因此,当它在该文件夹下找到 ojdbc.jar 时,它只适合我的应用程序,而不适合 weblogic 本身。因为 weblogic 有它自己的 ojdbc jar 并且不知何故,它只是扩展了 OracleCallableStatement 类以从它自己的 ojdbc jar 包装它们。因为我有一个单独的 ojdbc jar,在运行时,它无法将它转换为我的 jar 的 OracleCallableStatement。当我删除 web-inf/lib 下的 jar 并将有关 jdbc 连接和语句部分的责任交给 weblogic 时,它起作用了。
Thanks fellas
谢谢伙计们
回答by Narendra
I will give best solution, one approach is using <wls:prefer-web-inf-classes>false</ wls:prefer-web-inf-classes >
in weblogic.xml.
If you want true instead of false
in web-inf-classes
then another approach is remove ojdbcXX.jarin lib folder. While compiling program you can use any ojdbcXX.jarin classpath. But while deploying remove ojdbcXX.jarfrom lib. So that weblogic application server will use its own ojdbc and it will run successfully without any error.
我将给出最佳解决方案,一种方法是<wls:prefer-web-inf-classes>false</ wls:prefer-web-inf-classes >
在weblogic.xml 中使用。如果你想要 true 而不是false
inweb-inf-classes
那么另一种方法是删除lib 文件夹中的ojdbcXX.jar。编译程序时,您可以使用类路径中的任何ojdbcXX.jar。但是在部署时从 lib 中删除ojdbcXX.jar。这样 weblogic 应用程序服务器将使用它自己的 ojdbc 并且它会成功运行而没有任何错误。