• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AccessToUnderlying Connection Settings

 
Balakrishnan Nagarajan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

I am having one issue with the tomcat server when casting the tomcat.dbcp connection to Oracle connection.

The code looks like:

Connection conn = ds.getConnection();
OracleConnection underlyingConnection = null;
Connection dconn = (OracleConnection) ((DelegatingConnection) conn).getInnermostDelegate();


Here it will throws the Classcast exception (org.apache.tomcat.dbcp.dbcp **** to Oracle Connection)

The DelegatingConnection is from Tomcat DBCP jar.
I am using Tomcat 6.0.29 and 6.0.37.

When i googled, i got to know adding the parameter accessToUnderlyingConnection=True in Datasource fixes the problem. And it works as well.

But the site http://commons.apache.org/proper/commons-dbcp/configuration.html says,

Default is false, it is a potential dangerous operation and misbehaving programs can do harmfull things. (closing the underlying or continue using it when the guarded connection is already closed) Be carefull and only use when you need direct access to driver specific extentions.

NOTE: Do not close the underlying connection, only the original one.


Hence the fix which i proposed got rejected.

Tried with the different Tomcat version - 6.0.20, this Casting is working fine without adding any parameters in the XML files.

Could anyone help to clarify this?

Why it is working in 6.0.20 and not in 6.0.29 version?
And how to fix this issue in 6.0.29 version as well?


Thanks,
Bala N.




Thanks,
Bala N.
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most likely, it "worked" in 6.0.20 because of a bug that got fixed by release 6.0.29.

The whole reason for the rigamarole about Underlying Connection is because the actual JDBC Connection object that links to the Oracle server is not what gets returned from the connection pool. Instead what you get is a delegating extension class that mostly hands off all its method calls to the underlying (Oracle) Connection, except for the "close()" method, which simply returns the connection to the pool instead of actually severing the network linkage as the underlying Connection's close() method would.

There is really only one reason for obtaining the underlying Connection object, and that is so you can invoke methods that the underlying Connection object's driver provides that are not in the Java JDBC standards. While this can be useful, it is not something you want to do for trivial purposes. It locks you into a specific vendor, both in terms of the actual code, and in terms of where you can get support. Unless you absolutely, positively must, I don't recommend tying yourself to any vendor, even one as well-established as Oracle. You can never tell when someone in Accounting will balk at sending Larry Ellison another $100K and require you to dump your application on a PostgreSQL server instead, for example.
 
reply
    Bookmark Topic Watch Topic
  • New Topic