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.






1 comment:

  1. Hello Vikrant,

    Are you still with Mastek or have you quit...I came across your blog through mastek buzz & i was wondering if you are still here...

    On your technical blog thing, one of my friend had an idea that we are in the process of implementing. And by the looks of it, I am guessing that you might be interested too. This involves setting up a tech discussion blog, I do agree that there are loads, but then lets add one more & see where it leads us.

    my mastek id is devkumar.manakaparambil@mastek.com

    ReplyDelete