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

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

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

问题

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

以下是我的代码细节

我的 pom.xml

<dependency>
    <groupId>ojdbc</groupId>
    <artifactId>ojdbc</artifactId>
    <version>14</version>
    <type>ejb</type>
    <scope>provided</scope>
</dependency>

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

我的 DBConnection.java

CallableStatement statement;
Connection connection;
ArrayDescriptor descriptor;
Connection conn = datasourceObj.getconnection(dev);
try {
    statement = conn.prepareCall(callString);
    connection = ((WrappedConnection)conn).getUnderlyingConnection();
    descriptor = ArrayDescriptor.createDescriptor("NUM_ARRAY", connection);
}

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

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

然后我将下面的代码

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

替换为这段代码

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

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

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

    &lt;dependency&gt;
         &lt;groupId&gt;ojdbc&lt;/groupId&gt;
         &lt;artifactId&gt;ojdbc&lt;/artifactId&gt;
         &lt;version&gt;14&lt;/version&gt;
         &lt;type&gt;ejb&lt;/type&gt;
         &lt;scope&gt;provided&lt;/scope&gt; 
    &lt;dependency&gt;

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

    My DBConnection.java

    CallableStatement statement;
    Connection connection;
    ArrayDescriptor descriptor;
    Connection conn = datasourceObj.getconnection(dev);
    try {
        statement = conn.prepareCall(callString);
        connection = ((WrappedConnection) 
      conn).getUnderlyingConnection();
        descriptor = ArrayDescriptor.createDescriptor(&quot;NUM_ARRAY&quot;, 
       connection);
    }

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

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

with this piece of code

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:

确定