ClassCastException: oracle.jdbc.driver.T4CConnection cannot be cast to oracle.jdbc.OracleConnection

huangapple 未分类评论89阅读模式
英文:

ClassCastException: oracle.jdbc.driver.T4CConnection cannot be cast to oracle.jdbc.OracleConnection

问题

当我尝试与Oracle数据库建立连接时,我遇到了这个问题。我的应用程序规格是java8 + ejb + jboss-eap-7.3 + oracle 12c

以下是我的代码细节

我的 pom.xml

  1. <dependency>
  2. <groupId>ojdbc</groupId>
  3. <artifactId>ojdbc</artifactId>
  4. <version>14</version>
  5. <type>ejb</type>
  6. <scope>provided</scope>
  7. </dependency>

我已经在路径 jboss-ep-7.3/modules/com/oracle/ojdbc/main 中的 module.xml 文件中添加了 "ojdbc6.jar"。

我的 DBConnection.java

  1. CallableStatement statement;
  2. Connection connection;
  3. ArrayDescriptor descriptor;
  4. Connection conn = datasourceObj.getconnection(dev);
  5. try {
  6. statement = conn.prepareCall(callString);
  7. connection = ((WrappedConnection)conn).getUnderlyingConnection();
  8. descriptor = ArrayDescriptor.createDescriptor("NUM_ARRAY", connection);
  9. }

在将此 EAR 部署到 jboss 7.3 后,我收到了以下错误

  1. Caused by: java.lang.ClassCastException:
  2. org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8 无法转换为 oracle.jdbc.OracleConnection

然后我将下面的代码

  1. connection = ((WrappedConnection)conn).getUnderlyingConnection();

替换为这段代码

  1. OracleConnection oracleConnection = (OracleConnection) conn.getClass().getMethod("getUnderlyingConnection").invoke(conn);

在进行了这个代码更改之后,我得到了

  1. ClassCastException: oracle.jdbc.driver.T4CConnection 无法转换为 oracle.jdbc.OracleConnection

我甚至尝试删除 classes12.jar,但是没有取得任何进展。对于 oracle19c,我需要做同样的操作。请提供您宝贵的意见,以解决这个问题。

英文:

When I am trying to get connection with an Oracle database, I am facing this issue. My application specs are java8 + ejb + jboss-eap-7.3 + oracle 12c

Please find my code details below

My pom.xml

  1. &lt;dependency&gt;
  2. &lt;groupId&gt;ojdbc&lt;/groupId&gt;
  3. &lt;artifactId&gt;ojdbc&lt;/artifactId&gt;
  4. &lt;version&gt;14&lt;/version&gt;
  5. &lt;type&gt;ejb&lt;/type&gt;
  6. &lt;scope&gt;provided&lt;/scope&gt;
  7. &lt;dependency&gt;

I have added "ojdbc6.jar" in module.xml file from the path jboss-ep-7.3/modules/com/oracle/ojdbc/main.

  1. My DBConnection.java
  2. CallableStatement statement;
  3. Connection connection;
  4. ArrayDescriptor descriptor;
  5. Connection conn = datasourceObj.getconnection(dev);
  6. try {
  7. statement = conn.prepareCall(callString);
  8. connection = ((WrappedConnection)
  9. conn).getUnderlyingConnection();
  10. descriptor = ArrayDescriptor.createDescriptor(&quot;NUM_ARRAY&quot;,
  11. connection);
  12. }

After deployed this EAR into jboss 7.3, I got the below error

> Caused by: java.lang.ClassCastException:
> org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8 cannot be cast
> to oracle.jdbc.OracleConnection

And I replace the below code

  1. connection = ((WrappedConnection) conn).getUnderlyingConnection();

with this piece of code

  1. OracleConnection oracleConnection = (OracleConnection) conn.getClass().getMethod(&quot;getUnderlyingConnection&quot;).invoke(conn);

After this code change am getting

> ClassCastException: oracle.jdbc.driver.T4CConnection cannot be cast to
> oracle.jdbc.OracleConnection

I checked even removing the classes12.jar but no progress on that. The same I need to do for oracle19c. Please give your valuable comments to sort out this.

huangapple
  • 本文由 发表于 2020年8月15日 02:22:03
  • 转载请务必保留本文链接:https://java.coder-hub.com/63418148.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定