tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Merrill Cornish <>
Subject Another Try at MySQL Connection Pooling
Date Tue, 10 Feb 2004 22:24:43 GMT
I'm running 
  * Tomcat 5.0.18 running as a Wndows service, 
  * MySQL 4.0.16 running as a Windows service, and 
  * MySQL Connector/J 3.0.10 stable 
all on Windows 2000 Server, which is where I'm also doing the testing (i.e., on localhost).

A number of tomcat-user mailing list denizens have given me snippets of XML to put in various
places. Nothing worked.  So I tried following the "MySQL Configuration" example from
After all changes were made to server.xml, web.xml and timesheet.xml (the <context>
fragment under conf/Catalina/localhost), I restarted Tomcat and tried to login (the first
action that would have had to touch the MySQL database).

I got the following errorPage:

> At Timesheet.Util.errorPage( there occurred a
> java.lang.Exception: A fatal exception occurred while retrieving login name and pass
phrase because...
> At Timesheet.Util.getSqlConnection( there occurred a
> java.lang.Exception: Unable to establish a MysqlDataSource connection for ResourceLine
name "jdbc/TimesheetsDB" >because...
> At org.apache.naming.NamingContext.lookup( there occurred a
> javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

OK, that seems to say it doesn't know what the name "jdbc/TimesheetsDB" is.  Tomcat has written
nothing to stderr.log and stdout.log shows a clean startup, so Tomcat itself isn't too perturbed.
 stdout.log includes the following line:

> INFO: Processing Context configuration file URL file:C:\Program Files\Apache Group\Tomcat

implying that my timesheet.xml context fragment file was found and processed.  The Timesheet
application log file contains the following:

> 2004-02-10 16:20:05 NamingContextListener[/Catalina/localhost/timesheet]:   Resource
parameters for jdbc/TimesheetsDB = ResourceParams[name=jdbc/TimesheetsDB, parameters={factory=org.apache.commons.dbcp.BasicDataSourceFactory,
password=All41a14all, maxWait=10000, maxActive=100,,
username=timesheet_app, maxIdle=30}]

> 2004-02-10 16:20:05 NamingContextListener[/Catalina/localhost/timesheet]:   Adding resource
ref jdbc/TimesheetsDB

> 2004-02-10 16:20:05 NamingContextListener[/Catalina/localhost/timesheet]:   ResourceRef[className=javax.sql.DataSource,factoryClassLocation=null,factoryClassName=org.apache.naming.factory.ResourceFactory,{type=scope,content=Shareable},{type=auth,content=Container},{type=factory,content=org.apache.commons.dbcp.BasicDataSourceFactory},{type=url,content=jdbc:mysql://localhost/Timesheets?autoReconnect=true&socketFactory=com.mysql.jdbc.NamedPipeSocketFactory},{type=password,content=All41a14all},{type=maxWait,content=10000},{type=maxActive,content=100},{type=driverClassName,},{type=username,content=timesheet_app},{type=maxIdle,content=30}]

> 2004-02-10 16:20:05 NamingContextListener[/Catalina/localhost/timesheet]:   Resource
parameters for UserTransaction = null

[Blank lines added for clarity.]  As per the instructions in the jndi-datasource-examples-howto.html
page, my web.xml file has the following addition

>  <resource-ref>
>     <description>MySql Connection Pool</description>
>     <res-ref-name>jdbc/TimesheetsDB</res-ref-name>
>     <res-type>javax.sql.DataSource</res-type>
>     <res-auth>Container</res-auth>
>  </resource-ref>

immediately after the <error-page> element and immediately before the <security-constraint>

Now that I am using the timesheet.xml <context> fragment file, server.xml is unchanged
except that I have modified it to use port 80 in place of 8080 and port 443 in place of 8443.

The timesheet.xml <context> fragment file looks like this:

<Context path="/timesheet" docBase="timesheet" debug="9" reloadable="true"
         crossContext="true" displayName="ConnectTel Timesheet Application">
  <Logger className="org.apache.catalina.logger.FileLogger"
          prefix="localhost_timesheet_log." suffix=".txt" timestamp="true"/>
  <Resource name="jdbc/TimesheetsDB" auth="Container" type="javax.sql.DataSource"/>
  <ResourceParams name="jdbc/TimesheetsDB">
      <name>maxActive</name> <!-- max db connections in the pool -->
      <value>100</value>     <!-- 0 implies no limit -->
      <name>maxIdle</name>   <!-- max idle db connections to retain in pool
      <value>30</value>      <!-- 0 implies no limit -->
      <name>maxWait</name>   <!-- max wait for connection before throwing exception
      <value>10000</value>   <!-- -1 implies no limit (time is in milliseconds)

       <name>driverClassName</name> <!-- Class name for mm.mysql JDBC driver

I apologize for being so verbose, but I'm trying to provide all of the relevant information
in the initial message.  Does anyone see what I've missed?  The example in jndi-datasource-examples-howto.html
does NOT look like the other things I was told to do.  (?)


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message