tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Stevenson <dstev...@rochester.rr.com>
Subject Re: Tomcat 4.1: Setting Up Connection Pooling, Adding Resource to server.xml,
Date Sat, 27 Nov 2004 01:45:10 GMT
I missed the following important information that was in the Tomcat
documentation, that wasn't in the book I was reading. I am currently
getting the following exception in my log file when executing a servlet
that obtains a DataSource using the JNDI InitialContext. I previously
thought it might be a class not defined exception because I didn't
supply the connection pooling .jar files as required by the
instructions.

2004-11-26 20:15:24 org.apache.catalina.INVOKER.ClientListPooledServlet:
ClientListPooledServlet.init:
javax.naming.NameNotFoundException: Name java:comp is not bound in this
Context
        at
org.apache.naming.NamingContext.lookup(NamingContext.java:811)
        at
org.apache.naming.NamingContext.lookup(NamingContext.java:194)
        at javax.naming.InitialContext.lookup(InitialContext.java:347)
        at ClientListPooledServlet.init(ClientListPooledServlet.java:25)

>>From ClientListPooledServlet.java. Line 25 is the one with the new
InitialContext () constructor call.

        public void init ( ServletConfig config )
                throws ServletException
        {
                super.init ( config ) ;
                log ( "ClientListPooledServlet.init entered" ) ;
                try
                {
                        // Context initCtx = new InitialContext () ;
                        // Context envCtx = (Context) initCtx.lookup (
"java:comp/env" ) ;
                        // ds = (DataSource) envCtx.lookup (
"jdbc/tomcatbook" ) ;
                        ds = (DataSource) new InitialContext ().lookup (
"java:comp/env/jdbc/tomcatbook" ) ;
                }
                catch ( Exception e )
                {
                        log ( "ClientListPooledServlet.init: " +
e.getMessage () ) ;
                        log ( "ClientListPooledServlet.init: ", e ) ;
                        throw new UnavailableException ( e.getMessage ()
) ;
                }
                log ( "ClientListPooledServlet.init exiting" ) ;
        }



DBCP uses the Jakarta-Commons Database Connection Pool. It relies on
number of Jakarta-Commons componenets:

    * Jakarta-Commons DBCP 1.0
    * Jakarta-Commons Collections 2.0
    * Jakarta-Commons Pool 1.0

These jar files along with your the jar file for your JDBC driver should
be installed in $CATALINA_HOME/common/lib.

I don't know if these versions are close enough, or not.
If not, I can go through the Jakarta Archives looking for
closer versions.

[david@galileo logs]$ ll -rt $CATALINA_HOME/common/lib
...
-rw-r--r--    1 david    stevenson   175426 Nov 26 20:06
commons-collections-2.1.1.jar
-rw-r--r--    1 david    stevenson    42492 Nov 26 20:06
commons-pool-1.2.jar
-rw-r--r--    1 david    stevenson   107631 Nov 26 20:08
commons-dbcp-1.2.1.jar

Based on the Tomcat Documentation, I revamped the server.xml
configuration (I haven't modified this yet to include the
instructions under Preventing dB connection pool leaks in
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html).

  <Context className="org.apache.catalina.core.StandardContext"
cachingAllowed="true"
    charsetMapperClass="org.apache.catalina.util.CharsetMapper"
cookies="true"
    crossContext="false" debug="9" docBase="tomcatbook"
    mapperClass="org.apache.catalina.core.StandardContextMapper"
    path="/tomcatbook" privileged="false" reloadable="true"
swallowOutput="false"
    useNaming="false"
wrapperClass="org.apache.catalina.core.StandardWrapper"
displayName="Mastering Tomcat Development"
 >
    <Logger className="org.apache.catalina.logger.FileLogger"
      prefix="localhost_tomcatbook_log." suffix=".txt"
      timestamp="true"/>
    <Resource name="jdbc/tomcatbook" auth="Container"
type="javax.sql.DataSource" >
      <ResourceParams name="jdbc/tomcatbook">
        <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>tomcat</value>
        </parameter>
        <parameter>
           <name>password</name>
          <value>RealPasswordOmitted</value>
        </parameter>
        <parameter>
          <name>driverClassName</name>
          <value>com.mysql.jdbc.Driver</value>
        </parameter>
        <parameter>
          <name>url</name>
         
<value>jdbc:mysql://localhost/tomcatbook?autoReconnect=true</value>
        </parameter>
      </ResourceParams>
    </Resource>
  </Context>




$ more $CATALINA_HOME/webapps/tomcatbook/WEB-INF/web.xml
...
        <resource-ref>
                <description>
                        This is a reference to the data source we use
                        to talk to the database configured in the
server.xml file.
                </description>
                <res-ref-name>jdbc/tomcatbook</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
        </resource-ref>
...

=============================================================
Server Information
Tomcat Version		Apache Tomcat/4.1.24-LE-jdk14
JVM Version		1.4.2-b28
JVM Vendor		Sun Microsystems Inc.
OS Name			Linux 	
OS Version		2.4.20-31.9
OS Architecture		i386
MySQL			mysql-standard-4.0.18-pc-linux-i686
			mysql-connector-java-3.0.11-stable
=============================================================


David Stevenson


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message