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

4 thoughts on “Tomcat 6 using JNDI global DBCP

  1. Hi maxi326 I have been strugling with this for two days now. still couldn’t get it working, I’m using tomcat 6 Msql 5.0XX with apche2 2.28 (proxy).
    I cpied an pasted with changing “jdbc/TestDB” to “jdbc/DBTest” where DBTest is the folder name under webapps.
    my database name is javatest as the example said.
    Tell me what am I doing wrong here.
    The error message says:
    {{org.apache.jasper.JasperException: java.lang.UnsupportedOperationException: Not supported by BasicDataSource}}


  2. Hi morgan,
    I think my post is somewhat miss leading.
    Sorry about that. I will edit this post again when I got home.
    jdbc/TestDB has nothing to do with you webapps.
    It is the name for your connection pool resource, this is what is menas base on my understanding.
    So, it should not be your webapps folder name.
    and java:comp/env/jdbc/TestSpring in my post should be java:comp/env/jdbc/TestDB if you what those setting to work together.

    As for your exception, I am not sure what I mention above would fix it.
    If you have further question, you may email the whole exception log to me and see if I could help.

  3. Hi maxi326
    I’m using Fedora LINUX
    I get it working now. There is two small tricks you need them.
    1- edit the etc/hosts file on the linux server and make sure that the local host comes before the localhost.localadmin in the first line.
    2- edit the my.cnf file of mysql and comment out the skip-networking line.
    This file might be named my-huge, large, medium or my-small.cnf Or you might have all of them under you mysql ionstallation.

  4. Hi Morgan,

    I get it now, because I am using windows base with xampp, I almost skip all server setting. For linux I understand you need to set the host, if you are not using lampp, you will need to do mysql and apache configuration.
    I miss that part. I have only done that once long time ago.
    Thank you for your useful information. I will try to do it on linux when I have time. Thank you ^^.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s