jump to navigation

JNDI Oracle and Tomcat 5 July 5, 2006

Posted by maxmil in : Java,Oracle,tomcat , trackback

Been having problems setting up a JNDI oracle datasource in tomcat 5. With apaches common-dbcp i was able to use the getConnection() method of java.sql.Datasource but the getConnection(String username, String password) method ALWAYS returns a java.lang.UnsupportedOperationException.

From what i have seen on the web this is a limitation of the apache common connection pool. However for Oracle there is another factory that is bundled within classes12.jar that you can use. I found the solution here…. http://www.microdeveloper.com/html/JNDI_Orcl_Tomcat.html

Basically its just a question of specifying the type of the datasource as oracle.jdbc.pool.OracleDataSource and the connection pool factory as oracle.jdbc.pool.OracleDataSourceFactory.

This is my context.xml

<?xml version='1.0' encoding='utf-8'?>
<Context docBase="E:/work/proj/vaesa-st/bo/webroot" path="/soporte-tecnico/backoffice" reloadable="true" debug="1">
<Resource name="jdbc/SoporteTecnico_DataSource" auth="Container"
type="oracle.jdbc.pool.OracleDataSource"/>
<ResourceParams name="jdbc/SoporteTecnico_DataSource">
<parameter>
<name>factory</name>
<value>oracle.jdbc.pool.OracleDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@193.106.32.211:1521:VAESA</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>username</name>
<value>soportetecnico</value>
</parameter>
<parameter>
<name>password</name>
<value>vaesa</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
</Context>

and from my web.xml

<resource-ref>
<description>Soporte Tecnico datasource</description>
<res-ref-name>jdbc/SoporteTecnico_DataSource</res-ref-name>
<res-type>oracle.jdbc.pool.OracleDataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

and the code connection snippet

Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/SoporteTecnico_DataSource");
conn = ds.getConnection("xxx", "xxx");

Comments»

no comments yet - be the first?