how to use tomcat datasources

satya - Monday, February 12, 2007 5:48:32 PM

an onjava article on the subject

an onjava article on the subject

satya - Monday, February 12, 2007 5:58:54 PM

tomcat reference

tomcat reference

satya - Monday, February 12, 2007 6:38:36 PM

JDBC 2.0 tutorial

JDBC 2.0 tutorial

satya - Monday, February 12, 2007 6:53:14 PM

jdbc odbc bridge 1.4.2 to see if it supports data sources

jdbc odbc bridge 1.4.2 to see if it supports data sources

satya - Monday, February 12, 2007 10:22:29 PM

Register a resource in server.xml

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

<Resource name="jdbc/TestDB" auth="Container"
   type="javax.sql.DataSource" removeAbandoned="true"
   removeAbandonedTimeout="30" maxActive="100"
   maxIdle="30" maxWait="10000" username="kunal"
   password="java_facier"
   driverClassName="com.mysql.jdbc.Driver"
   url="jdbc:mysql://localhost/dbcptest"/>

</Context>

satya - Monday, February 12, 2007 10:27:09 PM

in web.xml

<listener>
        <listener-class> com.onjava.dbcp.DBCPoolingListener</listener-class>
</listener>

<!-- This component has a dependency on an external resource-->
 <resource-ref>
      <description> DB Connection Pooling</description>
      <res-ref-name> jdbc/TestDB</res-ref-name>
      <res-type> javax.sql.DataSource</res-type>
      <res-auth> Container</res-auth>
  </resource-ref>

<servlet>
        <servlet-name> EnrolledStudents</servlet-name>
        <servlet-class> com.onjava.dbcp.CourseEnrollmentServlet</servlet-class>
        <load-on-startup> 1</load-on-startup>
</servlet>

<servlet-mapping>
        <servlet-name> EnrolledStudents</servlet-name>
        <url-pattern> /enrollment.do</url-pattern>
</servlet-mapping>

satya - Monday, February 12, 2007 10:29:15 PM

understand servlet context listener interface

understand servlet context listener interface

satya - Monday, February 12, 2007 10:35:46 PM

Getting a datasource object

    // Obtain our environment naming context
    Context envCtx = (Context) new InitialContext().
    lookup("java:comp/env");

    // Look up our data source
    DataSource  ds = (DataSource) envCtx.lookup
       ("jdbc/TestDB");

satya - Monday, February 12, 2007 10:53:54 PM

what is env context in jndi?

what is env context in jndi?

satya - Monday, February 12, 2007 11:25:26 PM

How to specify the connection manager for Aspire

request.AppObjects.connectionManager.className=com.ai.db.cpjndi.ConnectionPoolConnectionManager5

satya - Monday, February 12, 2007 11:25:46 PM

Nothing else is required

Nothing else is required

satya - Monday, February 12, 2007 11:26:22 PM

The databasename is lowercased

So make sure the tomcat resource names are lower cased after the jdbc/

satya - Monday, February 12, 2007 11:26:52 PM

Follow the tomcat how to to place the needed jar files where they go

Follow the tomcat how to to place the needed jar files where they go

satya - Monday, February 12, 2007 11:27:56 PM

You need the build 23.5

You need the build 23.5

satya - Tuesday, February 13, 2007 9:50:09 AM

The basic dbcp jar files seems to be in the tomcat/common/lib directory

No need to copy these jar files. The basic jars to check for are

dbcp
pool
commons collections
jndi naming jar files

satya - Tuesday, February 13, 2007 9:50:31 AM

Tomcat recommends that the jdbc jar files be in commons/lib and be named *.jar

Tomcat recommends that the jdbc jar files be in commons/lib and be named *.jar

satya - Tuesday, February 13, 2007 10:16:48 AM

How to preload the dbcp with a preset number of connections?

How to preload the dbcp with a preset number of connections?

satya - Tuesday, February 13, 2007 10:17:11 AM

Have the initiaizer get the datasource before hand

Have the initiaizer get the datasource before hand

satya - Tuesday, February 13, 2007 10:20:44 AM

Document each property of the dbcp pool. locate a ref document

Document each property of the dbcp pool. locate a ref document

satya - Tuesday, February 13, 2007 10:21:04 AM

at least use the preload data sources in aspire

at least use the preload data sources in aspire

satya - Tuesday, February 13, 2007 6:28:15 PM

See this note

I am using Tomcat5.0.28. I have also faced the same problem and could able to solve through the following steps.

1. Created Datasource using Manager application which in turn create datasource elements in server.xml under .

2. Navigate to D:\jakarta-tomcat-5.0.28\conf\Catalina\localhost\.xml file and inserted the following:

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

and restarted the Tomcat, it is picking up now. It worked fine even after I deleted the datasource configuration from web.xml of the application.

satya - Tuesday, February 13, 2007 6:47:37 PM

what worker in server.xml

<Context path="/akc" docBase="w:/akc" debug="0">
      
  <Resource name="jdbc/reportsdb"
               auth="Container"
               type="javax.sql.DataSource"/>

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

    <!-- Maximum number of dB connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to 0 for no limit.
         -->
    <parameter>
      <name>maxActive</name>
      <value>10</value>
    </parameter>

    <!-- Maximum number of idle dB connections to retain in pool.
         Set to -1 for no limit.  See also the DBCP documentation on this
         and the minEvictableIdleTimeMillis configuration parameter.
         -->
    <parameter>
      <name>maxIdle</name>
      <value>5</value>
    </parameter>

    <!-- Maximum time to wait for a dB connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->
    <parameter>
      <name>maxWait</name>
      <value>10000</value>
    </parameter>

    <!-- MySQL dB username and password for dB connections  -->
    <parameter>
     <name>username</name>
     <value>none</value>
    </parameter>
    <parameter>
     <name>password</name>
     <value>none</value>
    </parameter>

    <parameter>
       <name>driverClassName</name>
       <value>sun.jdbc.odbc.JdbcOdbcDriver</value>
    </parameter>
    
    <!-- The JDBC connection url for connecting to your MySQL dB.
         The autoReconnect=true argument to the url makes sure that the
         mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
         connection.  mysqld by default closes idle connections after 8 hours.
         -->
    <parameter>
      <name>url</name>
      <value>jdbc:odbc:akc-reportsDB</value>
    </parameter>
  </ResourceParams>

      
</Context>

satya - Tuesday, February 13, 2007 6:51:29 PM

dbcp documentation for the tags

dbcp documentation for the tags

satya - Tuesday, February 13, 2007 6:56:08 PM

tomacat release warnings

Please note that JNDI resource configuration has changed somewhat between Tomcat 5.0.x and Tomcat 5.5.x. You will most likely need to modify your JNDI resource configurations to match the syntax in the example below in order to make them work in Tomcat 5.5.x.

satya - Tuesday, February 13, 2007 7:09:16 PM

tomcat 5028 comes with dbcp 121

tomcat 5028 comes with dbcp 121

satya - Tuesday, February 13, 2007 7:09:40 PM

that means it supports the initial set of of connections

that means it supports the initial set of of connections

satya - Wednesday, February 14, 2007 9:26:05 AM

here is the source code for the connectionpool wrapper in aspire

here is the source code for the connectionpool wrapper in aspire