Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Saturday, July 10, 2010

Calling Oracle Specific Stuff in WebSphere

When testing our application on Websphere, we got the following exception:

java.lang.ClassCastException: com.ibm.ws.rsadapter.jdbc.wsjdbcconnection incompatible with oracle.jdbc.oracleconnection

This occurs since we need the OracleSpecific connection object here, rather than the websphere wrapper around it?

However, how to get this object.

A quick search on the web revealed the following command to get the connection:

connection = (Connection) WSJdbcUtil.getNativeConnection((WSJdbcConnection)dataSource.getConnection());

The requisite jars are in the WEBSPHERE_HOME/plugins folder(search for rsadapterapi.jar which is itself embedded in some other jar).

However, as many of the sites noted, that the connection we got was already closed. Why was this?

Then it struck us. The connection object this returns is the physical connection object and if we call connection.close() which we did, it would end up closing the physical connection.

That means, the next datasource.getConnection(), could actually return a closed connection?

The trick is to use the native connection object for what is needed, but to not close it. This could mean code change in some applications, and we handled this by creating proxy classes for Oracle Specific classed.

But, now we are riddled with code incompatible with different application servers.

So much for J2EE and the much touted Write One Run Anywhere paradigm.