问题描述
我正在尝试连接到在WebSphere上运行的Java应用程序内的Oracle数据库。我需要能够创建一个数组描述符以用于对过程的调用。
I am trying to connect to an Oracle database inside a Java application running on WebSphere. I need to be able to create an array descriptor to use in a call to a procedure.
代码如下所示:
Connection conn=null;
ArrayDescriptor arrayDescriptor;
Connection tmpCon = jdbcTemplate.getDataSource().getConnection();
conn = WSCallHelper.getNativeConnection(tmpCon);
arrayDescriptor = ArrayDescriptor.createDescriptor("t_my_array",conn);
IDs = new oracle.sql.ARRAY(arrayDescriptor, conn, list.toArray());
调用 ArrayDescriptor.createDescriptor
的行抛出类抛出异常
The line that calls ArrayDescriptor.createDescriptor
throws a class cast exception
java.lang.ClassCastException: oracle.jdbc.driver.LogicalConnection incompatible with oracle.jdbc.OracleConnection
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:149)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:115)
使用调试器完成此操作后,我可以看到 conn
绝对是 oracle.jdbc.driver.LogicalConnection
。问题是我实际上无法在我的代码中引用 LogicalConnection
,因为该类不是公共的,所以我不能只做这样的事情:
Walking through this with the debugger, I can see that conn
is definitely a oracle.jdbc.driver.LogicalConnection
. The problem is I can't actually reference LogicalConnection
in my code because that class is not public, so I can't just do something like this:
arrayDescriptor = ArrayDescriptor.createDescriptor("t_my_array",((LogicalConnection)conn).getWrapper());
。
这个:
arrayDescriptor = ArrayDescriptor.createDescriptor("t_my_array",((oracle.jdbc.driver.OracleConnection)conn).getWrapper());
还会返回一个类强制转换异常:
also returns a class cast exception:
java.lang.ClassCastException: oracle.jdbc.driver.LogicalConnection incompatible with oracle.jdbc.driver.OracleConnection
我需要一个 OracleConnection
对象,但我似乎无法从返回给我的 LogicalConnection
中获取一个。有没有人见过这个?我觉得我错过了一些非常明显的东西,但也许我只需要另外一杯咖啡...
I need to have an OracleConnection
object, but I can't seem to get one from the LogicalConnection
that gets returned to me. Has anyone ever seen this before? I feel I'm missing something really obvious here, but maybe I just need another cup of coffee...
推荐答案
@Alex普尔指出我正确的方向。 Maven包含一个Oracle jar版本10.2.0.1.0,而WebSphere有相同的jar,但是版本为10.2.0.4.0。
@Alex Poole pointed me in the right direction. Maven was including an Oracle jar, version 10.2.0.1.0, and WebSphere had the same jar, but version 10.2.0.4.0.
修复POM之后10.2.0.1.0版本的jar没有部署,问题似乎得到了解决。
After fixing the POM so that the 10.2.0.1.0 version jar didn't get deployed, the problem seems to be resolved.
这篇关于获取oracle.jdbc.driver.LogicalConnection,需要oracle.jdbc.OracleConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!