Reputation: 181
Am using Websphere 18 Liberty Version. When am trying to unwrap java.sql.connection to oracle.jdbc.OracleConnection I get the
`DSRA9122E: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@d3t7e556 does not wrap any objects of type oracle.jdbc.OracleConnection
In sever.xml file am using ojdbc7.jar for datasource, also in application I added same jar from the same location. Still am facing the issue. I referred all links WSJDBCConnection does not wrap objects of type oracle.jdbc.OracleConnection like this. Still am facing the same issue.
Upvotes: 0
Views: 1747
Reputation: 119
I am posting it because I was unable to find a solution with the above reference. Even in the liberty documentation it's mentioned that for ear, war you should add
<application location="myApp.war" >
<classloader commonLibraryRef="OracleLib"/>
</application>
In my server.xml, this tag was different
<EnterpriseApplication id="myApp" location="myApp.war" name="myApp" >
<classloader commonLibraryRef="OracleLib"/>
</EnterpriseApplication >
Posting it just for the reference, if anyone misses the above point like I did.
Upvotes: 1
Reputation: 1338
You don't need to unwrap to OracleConnection. You can use Connection object to establish the connection to the DB.
// Get a context for the JNDI look up
DataSource ds = getDataSource();
try (Connection connection = ds.getConnection()) {
{
executeBusinessLogicOnDatabase(connection));
......
}
connection.close();
}
Upvotes: 1
Reputation: 3484
In order for Connection.unwrap
to work properly, the Liberty DataSource and the Application must both load the vendor implementation class (oracle.jdbc.OracleConnection) from the same class loader.
Here is a simple example of how to configure both the dataSource and your application to use the same class loader to load from a single library that contains the Oracle JDBC driver,
<library id="OracleLib">
<fileset dir="${server.config.dir}/oracle"/>
</library>
<application location="myApp.war" >
<classloader commonLibraryRef="OracleLib"/>
</application>
<dataSource jndiName="jdbc/oracleDataSource">
<jdbcDriver libraryRef="OracleLib"/>
<properties.oracle .../>
</dataSource>
Upvotes: 4