【问题标题】:Getting oracle.jdbc.driver.LogicalConnection, need oracle.jdbc.OracleConnection获取oracle.jdbc.driver.LogicalConnection,需要oracle.jdbc.OracleConnection
【发布时间】:2014-01-21 21:59:37
【问题描述】:

我正在尝试连接到运行在 WebSphere 上的 Java 应用程序内的 Oracle 数据库。我需要能够创建一个数组描述符以在调用过程中使用。

代码如下所示:

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的行抛出类转换异常

java.lang.ClassCastException:oracle.jdbc.driver.LogicalConnection 与 oracle.jdbc.OracleConnection 不兼容 在 oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:149) 在 oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:115)

使用调试器浏览这个,我可以看到conn 绝对是oracle.jdbc.driver.LogicalConnection。问题是我实际上不能在我的代码中引用LogicalConnection,因为该类不是公开的,所以我不能只做这样的事情:

arrayDescriptor = ArrayDescriptor.createDescriptor("t_my_array",((LogicalConnection)conn).getWrapper());

.

还有这个:

arrayDescriptor = ArrayDescriptor.createDescriptor("t_my_array",((oracle.jdbc.driver.OracleConnection)conn).getWrapper());

还返回一个类转换异常:

java.lang.ClassCastException: oracle.jdbc.driver.LogicalConnection 与 oracle.jdbc.driver.OracleConnection 不兼容

我需要一个OracleConnection 对象,但我似乎无法从返回给我的LogicalConnection 中获得一个。有没有人见过这个?我觉得我在这里遗漏了一些非常明显的东西,但也许我只需要再喝一杯咖啡......

【问题讨论】:

  • 一些谷歌点击表明不兼容的驱动程序可能会导致这种情况。您的 WebSphere 设置中的某处、类路径中的某处或您的应用程序中是否有较早的 ojdbc 版本?
  • @AlexPoole:有趣的想法。我不认为我有不同版本的 ojdbc 库,但我会看看。在我开始编写代码以手动将数组传递给过程之前,该应用程序工作正常。
  • @AlexPoole:看来你是对的!
  • 好吧,谷歌和甲骨文论坛是对的...... *8-)
  • Google;当时的第一弹是thisthisthis。似乎有足够的相似性表明您可能有同样的问题。 (第四次命中是这个问题*8-)

标签: java oracle jdbc websphere


【解决方案1】:

@Alex Poole 为我指明了正确的方向。 Maven 包含一个 Oracle jar,版本 10.2.0.1.0,WebSphere 有相同的 jar,但版本为 10.2.0.4.0。

在修复 POM 以使 10.2.0.1.0 版本的 jar 没有被部署后,问题似乎得到了解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 2010-12-13
    • 2014-10-16
    相关资源
    最近更新 更多