This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Tomcat and the fly likes How to get underlying connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to get underlying connection" Watch "How to get underlying connection" New topic
Author

How to get underlying connection

nick alex
Greenhorn

Joined: May 01, 2008
Posts: 3
I am using DBCP for connection pooling and want to access the underlying connection(Physical connection).
Also how can I configure my context.xml for same
Any body there to help..


Cheers niCk
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You've added the DBCP libraries to your webapp or do you mean that you're using container managed connection pooling provided by Tomcat?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Have a look at the documentation. I'm sure there is a setting that allows access to the actual connection rather than the wrapper.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

DBCP and Tomcat instructions are here: http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

DBCP says you need to set the 'accessToUnderlyingConnectionAllowed' to true, sample code is provided.
http://commons.apache.org/dbcp/configuration.html
nick alex
Greenhorn

Joined: May 01, 2008
Posts: 3
Hi Ben,
I was using container managed connection pooling provided by Tomcat.
I switched to commons DBCP
As suggested by David
Connection dconn = ((DelegatingConnection) conn).getInnermostDelegate();
works..
Thanks Ben and David.

--Nick
[ May 02, 2008: Message edited by: nick alex ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Just a note:
Tomcat uses DBCP as its connection pool library.
You might not need to bring it in yourself.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get underlying connection
 
Similar Threads
using protable remote object's narrow
Session Listener
Apache Commons DBCP connection object problem
SOAP and java.net.SocketException
getting underlying oracle connection from Poolable connection