javaoraclejdbcwebspherewebsphere-7

WSJDBCConnection does not wrap objects of type oracle.jdbc.OracleConnection


I saw a similar question asked:

Issue while creating Oracle ARRAY Type in java using ArrayDescriptor

However my issue is that other coders on the team are using the same code and apparently it is working fine for them.

    Connection conn = null;
    Connection oracleConn = null;
    CallableStatement stmt = null;
    try {

        conn = this.getDataSource().getConnection();
        if ( conn.isWrapperFor(oracle.jdbc.OracleConnection.class)) {
            oracleConn = conn.unwrap(oracle.jdbc.OracleConnection.class);
        }

I did not develop this code, I found it odd they're unwrapping an OracleConnection into a regular Connection class. Bawwwt.

I've tried a whole boat load of things, but really this code is supposed to work as is.

Now the above code generates a null pointer later on when a prepared statement is called since the if statement never fires. I never make it inside that if statement,

However when I force myself to do an unwrapping I get:

java.sql.SQLException: DSRA9122E: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@35c735c7 does not wrap any objects of type oracle.jdbc.OracleConnection

The environment is running ojdbc14 and JVM 6.0. Setup in WebSphere

First time poster, so I apologize in advance if I am mucking something up.

EditRemoved two variables from code that don't matter


Solution

  • Double check your config. Your DataSource must not be pointing to an Oracle DB like you think it is. I tested your code and it will work if your DataSource is truly pointing to an Oracle DB.

    The isWrapperFor() method is trying to tell you that your Connection does not wrap OracleConnection, and that is also consistent with what the exception message is telling you.

    You can check the datasource product information like this:

    DatabaseMetaData metadata = conn.getMetaData();
    System.out.println("DB product:  " + metadata.getDatabaseProductName());
    System.out.println("JDBC Driver: " + metadata.getDriverName());