Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JDBC lookup with JNDI returns null

843854Jan 29 2004 — edited Mar 3 2004
Hi.

I am trying to connect to my mysql database server through JNDI like this:

DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");

and then access it from a JSP file running in apache tomcat 4.0.1.

but ds is null. What are the reasons? I have put the driver jar file in the class path and copied it into
the common/lib directory, I have put this in the server.xml file:

<Context path="/DBTest" docBase="DBTest" debug="5" reloadable="true" crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
timestamp="true"/>

<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/TestDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>

<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>

<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>

<parameter>
<name>username</name>
<value>root</value>
</parameter>
<parameter>
<name>password</name>
<value>mypwd</value>
</parameter>

<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>

<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/javatest?autoReconnect=true</value>
</parameter>
</ResourceParams>
</Context>


I have put this in the web.xml in my application:

<description>MySQL Test App</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

and I have of course started the mysql server. I got the example from a tutorial showing how to use DBCP for connection pooling in Java.

Any suggestions? Getting frustrated...

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 31 2004
Added on Jan 29 2004
42 comments
4,163 views