0

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

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

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("NUM_ARRAY", 
       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("getUnderlyingConnection").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.

  • 1
    Why are you getting the underlying connection, rather than just doing `OracleConnection oracleConnection = (OracleConnection) conn;` ? – Alex Poole Aug 14 '20 at 22:18
  • ojdbc6 => implies it should be used with Java6. For Java8 use ojdbc8. PS: classes12 is meant for Java 1.2 – ibre5041 Aug 15 '20 at 07:05
  • @AlexPoole even i tried the same but the result is Caused by: java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8 cannot be cast to oracle.jdbc.OracleConnection – Naren selva Aug 15 '20 at 15:40
  • @ibre5041 Still same issue Caused by: java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8 cannot be cast to oracle.jdbc.OracleConnection – Naren selva Aug 15 '20 at 15:41
  • Is `NUM_ARRAY` a [VARRAY](https://docs.oracle.com/database/121/LNPLS/composites.htm#GUID-E932FC04-C7AD-4562-9555-8BA05446C0B8)? Are you trying to map a java object to a VARRAY or vice-versa, i.e. map a VARRAY to a java object? Maybe you should describe what you want to achieve rather than ask how to fix the bug in your implementation? However if you insist on using your implementation, this may help: https://stackoverflow.com/questions/39571100/unable-to-get-an-oracle-connection – Abra Aug 15 '20 at 17:48
  • @Abra The actual implementation is ,looping the storedprocedure values and the return string is equals to an array means adding into Array to present in the view page. Please find the below code ref : for(Param parm: storedProcedureObj.getInParams()) { if("long[]".equals(param.getType()) { ArrayDescriptor descriptor= ArrayDescriptor.createDescriptor("NUM_ARRAY", connection); ARRAY arObj = new ARRAY(descriptor, connection, name); } } For java 6 it's working fine but java 8 exception throwing – Naren selva Aug 16 '20 at 12:54
  • Don't add question details in a comment. [edit] your question and add those details that appear in your comment. – Abra Aug 16 '20 at 12:56

0 Answers0