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

无人久伴 提交于 2019-12-12 18:09:52

问题


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


回答1:


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());


来源:https://stackoverflow.com/questions/34097407/wsjdbcconnection-does-not-wrap-objects-of-type-oracle-jdbc-oracleconnection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!