12 Replies Latest reply on Oct 12, 2012 7:11 PM by 828002

    java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection

      I am getting the following error

      ava.lang.ClassCastException: oracle.jdbc.driver.T4CConnection cannot be cast to weblogic.jdbc.extensions.WLConnection
      at com.fedex.enable.bizobj.BillingNotifyLocationUpdate.processUpdate(BillingNotifyLocationUp
      at com.fedex.enable.bizobj.BillingNotifyLocationUpdate.processLocationUpdate(BillingNotifyLo
      at com.fedex.enable.bizobj.AcctBillingNotifyImpl.processMessage(AcctBillingNotifyImpl.java:2
      at com.fedex.enable.bizobj.AcctBillingNotifyImpl.prepareAndProcessMsg(AcctBillingNotifyImpl.
      at com.fedex.enable.bizobj.AcctBillingNotifyImpl.processNotifyMsg(AcctBillingNotifyImpl.java
      at com.fedex.enable.ejb.MessageTest.processMessage(MessageTest.java:71)
      at com.fedex.enable.ejb.MessageTest.main(MessageTest.java:123)

      Code :

      locationV2Pub.updateLocation ( (OracleConnection) ((WLConnection) dbProc.getConnectionObject ()).getVendorConnection(),
                                                        Constants.ENABLE_TRUE, locationRec,
                                                        objectVersionNumberArr, x_return_status,
                                                        x_msg_count, x_msg_data) ;

      this code use to work in Weblogic 9.2 ... but erroring out in 10.3
        • 1. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
          Joe Weinstein-Oracle
          Something is odd here...
          If we assume that dbProc.getConnectionObject () directly returns a connection you get
          at that time from a WebLogic DataSource, then that object should be castable to a
          WLConnection, whereupon you can call the WLConnection method getVendorConnection(),
          which should return you the naked OracleConnection...

          Try separating each call and identifying the object you get before either casting or
          calling the desired method....
          • 2. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
            Hi joe,

            here is the complete details about dbproc.

            We have a java file with the name DBProcessor.java and in that file we mentioned all the connection types and then we will call where ever it require

            Code of openDBConnection in DBProcessor.java file
            public void openDBConnection (String lookupName) throws DatabaseException
            InitialContext initialContext = new InitialContext();
            DataSource dataSource = (DataSource) initialContext.lookup(lookupName);
            dbConnection = (Connection) dataSource.getConnection() ;

            if (AppLogger.isDebugEnabled ()) AppLogger.debug ("OPEN_A_NEW_DATABASE_CONNECTION") ;
            catch (SQLException sqlException)
            AppLogger.alert ("DATABASE_INACCESSIBLE") ; // OVO TEMPLATE STRING
            throw new DatabaseException ("" + sqlException.getErrorCode (), sqlException.getMessage (),
            sqlException) ;
            catch (Exception exception)
            AppLogger.alert ("DATABASE_INACCESSIBLE") ; // OVO TEMPLATE STRING
            throw new DatabaseException ("", exception.getMessage (), exception) ;

            DBProcessor dbProc = null ;

            dbProc = new DBProcessor () ;
            dbProc.openDBConnection (AppInit.getProperty ("enableDsName")) ;

            As company standards we are using WLconnection for DB connection and then typecasting to OracleConnection.

            Please let me know if you need more details .....
            • 3. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
              Joe Weinstein-Oracle
              that looks fine as such: I'd ask that you do this for me:

              Connection wlc = null; // best WLS JDBC practice: method-level connection

              try {

              wlc = dbProc.getConnectionObject ();
              System.out.println("getConnectionObject() returns a " + wlc.getClass() );
              if (!(wlc instanceof WLConnection)) System.out.println("Not a WLConnection!");

              Connection vc = ((WLConnection)wlc).getVendorConnection();
              System.out.println("getVendorConnection gives us a " + vc.getClass() );
              if ( !(vc instanceof OracleConnection)) System.out.println("Not an OracleConnection!");

              OracleConnection oc = (OracleConnection)vc;

              locationV2Pub.updateLocation ( vc, Constants.ENABLE_TRUE, locationRec,
              objectVersionNumberArr, x_return_status,
              x_msg_count, x_msg_data) ;

              wlc = null;
              finally {
              if (wlc != null) try {wlc.close();} catch (Exception ignore) {} // best WLS JDBC practice: close wls connection always
              • 4. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
                Hi Joe,

                Thank you for detailed reply.

                Let me try that and let you know ....
                • 5. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
                  Hi Joe,

                  I have tried with the following changes .... and it is working fine after setting the ojdbc14.jar file in classpath before weblogic.jar file.

                  But I guess this is not right way... becuase we are forcing to use old ojdbc14.jar (Weblogic 9.2 version file).....

                  Can you put your valuable comments on this ....

                       Object conObj = dbProc.getConnectionObject();
                       System.out.println("Class Name : "+conObj.getClass().getName());
                                 if(conObj instanceof OracleConnection) {
                            System.out.println("Inside If : before API : Class Name : "+conObj.getClass().getName());
                                 locationV2Pub.updateLocation ((OracleConnection) conObj,
                                                               Constants.ENABLE_TRUE, locationRec,
                                                               objectVersionNumberArr, x_return_status,
                                                               x_msg_count, x_msg_data) ;
                                 System.out.println("Inside If : after API : Class Name : "+conObj.getClass().getName());
                            }else {
                            System.out.println("Inside else If : before API : Class Name : "+conObj.getClass().getName());
                            //Typecast according to class name
                            locationV2Pub.updateLocation ( (OracleConnection) ((WLConnection) dbProc.getConnectionObject ()).getVendorConnection(),
                                                                    Constants.ENABLE_TRUE, locationRec,
                                                                    objectVersionNumberArr, x_return_status,
                                                                    x_msg_count, x_msg_data) ;
                            System.out.println("Inside else If : after API : Class Name : "+conObj.getClass().getName());

                       }catch (Exception e){
                       System.out.println ("BillingNotifyLocationUpdate::processUpdate===>During API Execution +" +e) ;

                  Out Put ::::
                  2010/03/19 18:19:53.490 DEBUG <(BillingNotifyLocationUpdate.java:313)> [35628696] -
                  BillingNotifyLocationUpdate::processUpdate===>Before API Execution

                  2010/03/19 18:19:53.491 DEBUG <(BillingNotifyLocationUpdate.java:331)> [35628696] -
                  Class Name : weblogic.jdbc.wrapper.PoolConnection_oracle_jdbc_driver_T4CConnection

                  2010/03/19 18:19:53.491 DEBUG <(BillingNotifyLocationUpdate.java:340)> [35628696] -
                  Inside else If : before API : Class Name : weblogic.jdbc.wrapper.PoolConnection_oracle_jdbc_driver_T4CConnection

                  2010/03/19 18:19:53.551 DEBUG <(MessageSelector.java:228)> [35628696] -

                  2010/03/19 18:19:53.551 INFO <(AppInit.java:156)> [35628696] -
                  SQL Name: updateStatusWithIdentifier.sql

                  2010/03/19 18:19:53.552 DEBUG <(DBProcessor.java:786)> [35628696] -
                  Types in DBProcessor:[12, 93, 12, 12, 12, 12]

                  2010/03/19 18:19:53.552 DEBUG <(DBProcessor.java:787)> [35628696] -
                  Values in DBProcessor:[F, 2010-03-19 18:19:53.551, 104262503, FX, accountBillingNotify, PBA]

                  2010/03/19 18:19:53.552 DEBUG <(DBProcessor.java:799)> [35628696] -
                  Input Type in DBProcessor:12

                  2010/03/19 18:19:53.552 DEBUG <(DBProcessor.java:807)> [35628696] -
                  Input Type is equal to Types.CHAR/Types.VARCHAR/Types.LONGVARCHAR in DBProcessor.

                  2010/03/19 18:19:53.552 DEBUG <(DBProcessor.java:799)> [35628696] -
                  Input Type in DBProcessor:93

                  2010/03/19 18:19:53.553 DEBUG <(DBProcessor.java:823)> [35628696] -
                  • 6. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
                    Joe Weinstein-Oracle
                    What is the full class you are using for OracleConnection? If it includes "driver.", remove that
                    and use the newer driver.
                    • 7. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
                      Hi Joe,

                      As you said... I have used the latest one import oracle.jdbc.OracleConnection; then I get the following compilation errors...

                      [javac] C:\StarTeam\GRS-GRCC\Test\EnableCode\enable\projects\enable\src\com\fedex\enable\bizobj\
                      AcctBaseNotifyCustProfAmtUpdate.java:141: updateCustProfileAmt(oracle.jdbc.driver.OracleConnection,j
                      l[],java.lang.String[],java.math.BigDecimal[],java.lang.String[]) in oracle.apps.ar.hz.v2api.HzCusto
                      merProfileV2Pub cannot be applied to (oracle.jdbc.OracleConnection,java.lang.String,oracle.apps.ar.h
                      [javac] customerProfileV2Pub.updateCustProfileAmt ((OracleConnection) ((WLConnection) dbP
                      roc.getConnectionObject ()).getVendorConnection(),
                      [javac] ^
                      [javac] C:\StarTeam\GRS-GRCC\Test\EnableCode\enable\projects\enable\src\com\fedex\enable\bizobj\
                      AcctBillingNotifyImpl.java:417: updateCustomerProfile(oracle.jdbc.driver.OracleConnection,java.lang.
                      .lang.String[],java.math.BigDecimal[],java.lang.String[]) in oracle.apps.ar.hz.v2api.HzCustomerProfi
                      leV2Pub cannot be applied to (oracle.jdbc.OracleConnection,java.lang.String,oracle.apps.ar.hz.v2api.
                      [javac] HzCustomerProfileV2Pub.updateCustomerProfile
                      ((OracleConnection) ((WLConnection) dbProcessor1.getConnectionObject ()).getVendorConnection(),

                      I have set my classpath as follows .

                      set LCP=C:/bea/wlserver_10.3/server/lib/webservices.jar;C:/bea/wlserver_10.3/server/lib/weblogic.jar;C:/bea/wlserver_10.3/server/lib/ojdbc6.jar;C:/bea/modules/org.apache.ant_1.6.5/lib/xml-apis.jar;c:/bea/wlserver_10.3/common/lib/log4j.jar;c:/bea/jrockit_160_05/lib/tools.jar;c:/bea/jrockit_160_05/jre/lib/rt.jar;
                      • 8. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
                        Joe Weinstein-Oracle
                        Your code seems riddled with 'oracle.jdbc.driver.OracleConnection' such as in that updateCustProfileAmt(oracle.jdbc.driver.OracleConnection,java.lang.String,oracle.apps.ar.hz.v2api.HzCustomerProfileV2Pub.CustProfileAmtRec,java.math.BigDecima
                        l[],java.lang.String[],java.math.BigDecimal[],java.lang.String[]) in oracle.apps.ar.hz.v2api.HzCusto

                        If you can't get rid of all of those references then
                        you're stuck with using an old and soon to be unsupported driver. Whatever you set your shell's classpath is irrelevant. WLS makes it's own classpath according to the scripts I mentioned. Read the startWebLogic script and follow the scripts it calls.
                        • 9. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
                          Hi Joe,

                          Upon your valuable suggestion... I have scanned each and every file of my project and every where I am refering to "import oracle.jdbc.*"

                          After looking into the error message deeply ... what I feel is point 1 is what the API is expecting parameters and point 2 is what we are sending to the API.
                          That means I am refering to correct JDBC driver i.e. oracle.jdbc.* but API class it self is designed to expect the parameters in old format.

                          API is given by ORACLE and it is from HZ.jar

                          Please correct me .. if I am wrong.

                          The reason why I am researching on this because... oracle support told me that .. it is not recomend to use ojdbc14.jar file with JDK1.6 version. This is a very high priority issue in my plate now ....

                          1) [javac] C:\StarTeam\GRS-GRCC\Test\EnableCode\enable\projects\enable\src\com\fedex\enable\bizobj\AcctBaseNotifyCustProfAmtUpdate.java:141:     updateCustProfileAmt(oracle.jdbc.driver.OracleConnection,

                          in oracle.apps.ar.hz.v2api.HzCustomerProfileV2Pub

                          2) cannot be applied to (oracle.jdbc.OracleConnection,

                          Please give your valuable suggestions ...
                          • 10. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
                            Joe Weinstein-Oracle
                            I'm saying that you should remove all mention of oracle.jdbc.driver.OracleConnection
                            from anywhere in your code. And if you're using JDK 1.6 you can use the ojdbc6.jar.
                            But if oracle applications themselves refer to oracle.jdbc.driver.OracleConnection,
                            then you need to get updated versions of those, or else you're stuck with the
                            older driver...
                            • 11. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
                              Hi Joe,

                              Quick question ....

                              Where can I find JAR files in JAVA_TOP ????

                              • 12. Re: java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection
                                resolved for me with below change

                                Please check your import statements in Java Class is below for connection variable

                                import oracle.jdbc.OracleConnection;