views:

550

answers:

0

I've been searching for a good example of how to configure a Oracle OCI pool connection in tomcat's server.xml (defining a JNDI resource) and subsequently how to use it.

Here's what I have now in conf\server.xml:

<Context docBase="ips" path="/ips" reloadable="true">
    <Resource name="jdbc/IPS_DB" 
              auth="Container" 
              type="javax.sql.DataSource"
              maxActive="100" 
              maxIdle="30" 
              maxWait="10000"
              username="ips" 
              password="password" 
              driverClassName="oracle.jdbc.driver.OracleDriver"
              url="jdbc:oracle:thin:@ips.oraclehost.net:1521:ips"/>
</Context>

and in WEB-INF\web.xml:

<resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/IPS_DB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

and to access the connection in code:

Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:comp/env");
DataSource db = (DataSource) envContext.lookup("jdbc/IPS_DB");
Connection con = db.getConnection();

I want to use a pool connection to reduce the context switching that happens every time a new connection is created as the code above is effectively everywhere (it's in a method that returns a connection) a DB connection is needed in the app I'm working on.

So far I've only been able to find what I think goes into server.xml:

<RESOURCES>
    <JDBCRESOURCE jndiname="jdbc/tpcwDB" 
                  poolname="TpcwPool"
                  enabled="true">
    <JDBCCONNECTIONPOOL name="TpcwPool"
                        datasourceclassname="oracle.jdbc.pool.OracleDataSource"
                        steadypoolsize="50" 
                        maxpoolsize="100" 
                        poolresizequantity="1"
                        idletimeout="0" 
                        maxwaittime="0"
                        connectionvalidationrequired="false"
                        connectionvalidationmethod="auto-commit"
                        validationtablename="string" 
                        failallconnections="false" >
        <PROPERTY name="URL"
                  value="jdbc:oracle:oci9:@(description=(address=(host=ips.oraclehost.net)
                         (protocol=tcp)(port=1521))(connect_data=(sid=ips)))">
        <PROPERTY name="user" value="ips">
        <PROPERTY name="password" value="password">
    </JDBCCONNECTIONPOOL>
</RESOURCES>

Since it's a JDBCConnectionPool or JDBCResource element instead of a Resource, I must have to access it a little differently, but I'm not sure what those differences are. Finally I'm not sure which of the jar files in {ORACLE_HOME}/jdbc/lib I need to include in my project, as I'm using the Oracle9iThinDrivers.jar now. Any help would be greatly appreciated.