TomcatExpert

Retrieving Inner Oracle Connections

posted by SpringSource on May 21, 2010 01:11 PM

Using DBCP or the connection pooling built into the Oracle JDBC driver implementation.

You should just be able to cast to the DBCP specific Connection class and from there retrieve the inner Oracle connection:

import org.apache.commons.dbcp.DelegatingConnection;
 
DelegatingConnection dc = (DelegatingConnection)conn;
OracleConnection oc = (OracleConnection)pc.getInnermostDelegate();

Note: If you are using Tomcat's built-in copy of DBCP then the import you will need is:

import org.apache.tomcat.dbcp.dbcp.DelegatingConnection;

Or you can use the connection pooling built into the Oracle JDBC driver implementation. This returns an Oracle connection. A simple setup would be:

<Resource auth="Container"
          connectionCacheName="CXCACHE"
          connectionCacheProperties="{MaxStatementsLimit=5,MinLimit=1, MaxLimit=1, ValidateConnection=true}"
          connectionCachingEnabled="true"
          description="Oracle Datasource"
          factory="oracle.jdbc.pool.OracleDataSourceFactory"
          name="jdbc/TestDB"
          user="default_user" 
          password="password"
          type="oracle.jdbc.pool.OracleDataSource"
          url="jdbc:oracle:thin:@//localhost:1521/orcl"
          />

For more than 10 years, SpringSource employees have been supporting Apache technologies, with unparalleled experience and commitment to the Apache Software Foundation. More than 400 of the Fortune 500 count on SpringSource to support their mission-critical business applications. Leaders of the Apache Software Foundation, including Board Members, work at SpringSource and dedicate a significant amount of time further developing the Apache Tomcat open source project. Over the last 2 years, 95% of the issues fixed in the Apache Tomcat project were fixed by SpringSource engineers. For more information on how SpringSource can help your enterprise, see the SpringSource website, or call 800/444-1935.

Comments

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.