Setting up Oracle JNDI Datasource on Tomcat

Leon van Tegelen 7
0 0
Read Time:1 Minute, 48 Second

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");

About Post Author

Leon van Tegelen

Consultant at AMIS
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

7 thoughts on “Setting up Oracle JNDI Datasource on Tomcat

  1. I configured it using:

    The MinLimit is inside connectionCacheProperties, but the pool I sometimes returns a null connection.
    So I am changing it to:

    And see what happens (OracleDataSource to OracleConnectionCacheImpl). But so far, it seems to be working fine after the change

  2. Hello, I have this question … If I only use the libraries concerning to the connection pooling from Oracle… do I have to pay for a license??, I know that if I deploy BC4J Apps (or in general ADF apps) into other Web servers like TomCat I have to pay for a license..but if I only use the OracleConnectionCacheImpl” and related clases to implement a pool……should I have to pay for that??

    thankss

  3. I just ran into this too, at the end of a long voyage of painful JNDI discovery.
    I was trying to use the Oracle RowSet implementation, and I hit this, even
    after I eliminated the minLimit.

    My take on what happens is that when you specify minLimit, the pool is initialised with the username and password that you specified, or didn’t specified in the resource description.

    The specific problem I had was because with a RowSet, you specify the datasource name, and you *can* specify the username and password, but that should be optional. In Oracle’s implementation though, the username and password default to “” instead of null; which of course didn’t match the original username and password.

    I fixed this once by specifying the credentials when I created the RowSet, but then I realised what was happening and set the username and password to null in the RowSet and everything started working:-)

    Hope this helps
    Gordon

  4. Hi

    context resource tags:

    factory
    oracle.jdbc.pool.OracleDataSourceFactory
    password
    tiger
    driverClassName
    oracle.jdbc.driver.OracleDriver
    url
    jdbc:oracle:thin:@localhost:1521:DEVDB
    username
    scott

    I am using jsp (with JSTL page) as below:

    < %@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
    < %@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


    select name,hphone,caddress from addr



    Oracle Test

    Results


    forEach var=”row” items=”${rs.rows}”>

    I am still getting : Unable to get connection, DataSource invalid: “java.sql.SQLException: User credentials doesn’t match the existing ones”

    Can you suggest me any solution.

    Regards

    Ajay

  5. Well… The really driving me nuts thingy had nothing to do with JNDI as such, but with the configuration of the Oracle DataSource supplying a minLimit parameter.
    Which in my opinion is a bug in the driver ….

  6. see reference from Lecture on JNDI

    An actual example of how someone set this up. In the spirit of the last few weeks here is a blog post from someone who set up a database connection: Setting up Oracle JNDI Datasource on Tomcat. Notice especially “It really drove me nuts”. Check with your psychiatrist before continuing in the field.

Comments are closed.

Next Post

ADF BC classes & methods overview

Steve Muench wrote up a superb overview of the most commonly used classes, interfaces & their methods in the ADF BC framework (formerly known as BC4J). You might want to check this out as it leads you straight to the stuff you need to write your apps, without getting lost […]
%d bloggers like this: