2 Replies Latest reply on Dec 11, 2015 3:23 AM by Anurag Ppp

    how to resolve JBOSS EAP 6.3.3 oracle.jdbc.driver.T4CConnection cannot be cast to oracle.jdbc.OracleConnection ???

    Anurag Ppp Newbie

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

        at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:105) [ojdbc6.jar:11.2.0.3.0]

        at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:73) [ojdbc6.jar:11.2.0.3.0]

        at com.test.service.dao.seriveDAO.getDashboardData(seriveDAO.java:39) [classes:]

       

      i tried using ojdbc6 and ojdbc14 jars  , but no luck unable to resolve this issue..,

        • 1. Re: how to resolve JBOSS EAP 6.3.3 oracle.jdbc.driver.T4CConnection cannot be cast to oracle.jdbc.OracleConnection ???
          Jay SenSharma Master

          Please see: http://docs.oracle.com/javase/6/docs/api/java/sql/Wrapper.html#isWrapperFor%28java.lang.Class%29

           

          isWrapperFor: 

               Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. Returns false otherwise. If this implements the interface then return true, else if this is a wrapper then return the result of recursively calling isWrapperFor on the wrapped object. If this does not implement the interface and is not a wrapper, return false. This method should be implemented as a low-cost operation compared to unwrap so that callers can use this method to avoid expensive unwrap calls that may fail. If this method returns true then calling unwrap with the same argument should succeed.

           

          So if your application code wants to get thew Vendor specific Database connection then please try the following code:  Edit your code "com.test.service.dao.seriveDAO.getDashboardData"  to cast the Connection as following:

           

            Connection con = dataSource.getConnection();
            if (con.isWrapperFor(OracleConnection.class)) {
              OracleConnection oraCon = con.unwrap(OracleConnection.class);
            } else {
              throw new Exception("Connection is Not Oracle Connection");
            }
          
          

           

           

          NOTE:    Also for "oracle.jdbc.driver.T4CConnection cannot be cast to oracle.jdbc.OracleConnection"   You need to make sure that  You are not packaging the ojdbc6.jar inside your application if you are getting connection from the DataSource.   Else due to multiple jars (one loaded by JBoss and another loaded by Application) it may cause the   ClassCast issue.

                         If you are placing ojdbc*.jar inside your applications WEB-INF/lib  and another copy your are deploying on JBoss as a module or as a deployable then you might face this issue because in that case the classloader will be different for those classes and might lead to the ClassCast issue so   try removing that JAR from the application if you are packaging it  Your application can refer to the deployed Driver JAR using jboss-deployment-structure.xml or using $WAR/META-INF/MANIFEST.MF   Dependencies.

           

          Regards

          Jay SenSharma

          1 of 1 people found this helpful
          • 2. Re: how to resolve JBOSS EAP 6.3.3 oracle.jdbc.driver.T4CConnection cannot be cast to oracle.jdbc.OracleConnection ???
            Anurag Ppp Newbie

            Thanks Jay SenSharma,


            I tried ur suggestion mentioned in NOTE section ... I T WORKED !!!

            1.I stopped packaging ojdbc6 jar in the war.

            2.i added the ojdbc6.jar module in JBOSS server modules directory.

            3. mentioned that in jboss-deployment structure xml..

            4. I deployed this time it Worked ....


            jboss-deployment structure xml.. used below..,

            =============================

            <?xml version="1.0" encoding="UTF-8"?>

            <jboss-deployment-structure>

              <deployment>

              <dependencies>

              <module name="org.jboss.ironjacamar.jdbcadapters" />

              <module name="oracle.jdbc" />

              </dependencies>

              </deployment>

            </jboss-deployment-structure>