2

I want to get the OracleConnection from a WsJdbcDataSource in an application running in WebSphere Application Server 9, but I'm not able to unwrap the connection.

I'm using Oracle ojdbc8 set up as a JDBC provider, and as here I've found some question answers suggesting to leave any driver library from the application out, I marked in my pom the ojdbc dependency is as 'provide'. I tried as well to check I'm actually dealing with an Oracle DataSource so I checked the following:

System.out.println("Class: " + conn.getMetaData().getClass());
System.out.println("Driver: " + conn.getMetaData().getDriverName());
System.out.println("Name: " + conn.getMetaData().getDatabaseProductName());
System.out.println("isWrapperFor OracleConnection: " + conn.isWrapperFor(OracleConnection.class));

/* Output: 
Class: com.ibm.ws.rsadapter.jdbc.WSJdbcDatabaseMetaData
Driver: Oracle JDBC driver
Name: Oracle
isWrapperFor OracleConnection: false
*/

Even though it's an Oracle Connection as I can see, "WsJdbcConnection does not wrap objects of type oracle.jdbc.OracleConnection".

  • Are you sure there are no other Oracle JDBC drivers packaged in your application? Generally if you are getting that it means there are two versions of the `OracleConnection` class loaded by different classloaders. I would also check that your Oracle JDBC provider is not [isolated](http://www-01.ibm.com/support/docview.wss?uid=swg21634612). – Alex Motley Aug 16 '19 at 20:59
  • @AlexMotley it's not isolated, I've just checked it. I'm exploring the war libs folder and there's nothing. Is there any other way I can notice? – Luciano Marti Aug 16 '19 at 21:15
  • look for other copies of ojdbc driver in WAS lib/* folders – F Rowe Aug 16 '19 at 23:22
  • Connection pools don't always allow you to unwrap to their physical connections (at least not without explicitly configuring that), because giving access to the physical connection allows you to do things with the connection that could break the expectations and requirements of the connection pool. Alternatively, you might be confronted with this problem: [Unwrap native oracle connection from WAS connection](https://www.ibm.com/developerworks/community/blogs/7e2e8015-bf72-43b6-bacd-36565b67febc/entry/Unwrap_native_oracle_connection_from_WAS_connection?lang=en) – Mark Rotteveel Aug 17 '19 at 05:38
  • There are no libraries coming from WAS that could conflict the ojdbc driver I provided. If there's any extra configuration needed I don't know what it could be, and I didn't find anything by myself. I'm NOT using Liberty so this is not a duplicate. – Luciano Marti Aug 21 '19 at 18:51

0 Answers0