Setting up Oracle JNDI Datasource on Tomcat html

Setting up Oracle JNDI Datasource on Tomcat

In one of the projects I’m involved in we have to make use of specific Oracle JDBC features. The application runs on Tomcat 5.0.27 and connects to the database using a JNDI datasource setup to use connection pooling . When setting this up based on info I found in Steve Muench ‘sBC4J Toy Story example I ran into some problems .

For some reason I got the following error:

“java.sql.SQLException: User credentials doesn’t match the existing ones”.

It really drove me nuts. Checking parameternames over and over, checking username and password … But together with Martijn Hinten of Cumquat I managed to track down the problem. This error only occurs if you specify the minLimit parameter, used to specify the minimum number of pooled connections the pool should have. If you ommit it everythings fine .. This is the minimum context file we needed to get the OracleConnectionCacheImpl working

<?xml version='1.0' encoding='utf-8'?>
<Context displayName="udo" docBase="C:/development/appservers/jakarta-tomcat-5.0.27/webapps/myContext" path="/myContext" workDir="workCatalinalocalhostmyContext">
  <Resource name="jdbc/myDataSource" type="oracle.jdbc.pool.OracleConnectionCacheImpl"/>
  <ResourceParams name="jdbc/myDataSource">
    <parameter>
      <name>factory</name>
      <value>oracle.jdbc.pool.OracleDataSourceFactory</value>
    </parameter>
    <parameter>
      <name>password</name>
      <value>****</value>
    </parameter>
    <parameter>
      <name>url</name>
      <value>jdbc:oracle:thin:@localhost:1521:***</value>
    </parameter>
    <parameter>
      <name>driverClassName</name>
      <value>oracle.jdbc.driver.OracleDriver</value>
    </parameter>
    <parameter>
      <name>user</name>
      <value>local_user</value>
    </parameter>
  </ResourceParams>
</Context>

Place this file under the name myContext.xml in tomcat_home/conf/Catalina/localhost. Now you should be able to use this Datasource from within the “myContext” web -application using the following code

InitialContext context = new InitialContext();
envContext = (Context) context.lookup("java:comp/env");
ds = (DataSource) envContext.lookup("jdbc/myDataSource");

7 Comments

  1. Luxspes August 24, 2009
  2. Luxspes August 24, 2009
  3. Luis Junes June 6, 2006
  4. Gordon February 2, 2006
  5. Ajay September 3, 2005
  6. Leon van Tegelen December 8, 2004
  7. Lucas December 8, 2004