Tomcat 6 using JNDI global DBCP

This setting gives me a hard time.

I have gone through Tomcat 6 document about JNDI and JDBC so many times.

But I get this work by reading many forums.

I think the documents provided by tomcat is confusing and maybe out of sync. to the current version.

I am going straight to the solution.

Add this in your tomcat\conf\server.xml, the parameters are set according to your situation


    <!-- Editable user database that can also be used by

         UserDatabaseRealm to authenticate users

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

               maxActive="100" maxIdle="30" maxWait="10000"

               username="root" password="" driverClassName="com.mysql.jdbc.Driver"



Add this to your tomcat\conf\context.xml

<ResourceLink name="jdbc/TestDB" global="jdbc/TestDB" type="javax.sql.DataSource"/>

Nothing needs to be done to you per-web web.xml.

It is not what tomcat documentation mention in server.xml <host><context>…</context></host>

Maybe that works for per-web-jndi setting but not for global one.

This look like easy setting, but it takes me lots of time.

P.S. I am newbie to tomcat, haha.

One more thing, If you are using Spring HibernateDaoSupport.

The value for jndiName for Tomcat is different from other like JBoss.

JBoss : java:jdbc/TestSpring

Tomcat: java:comp/env/jdbc/TestSpring

that is

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">