I don't know if there's a complete top-to-bottom guide, but here's
what I know from setting up connection pooling under 5.5.12:

1. The JDBC driver JAR must go in the common/lib directory (because
for connection pooling it needs to be accessible to both Tomcat and
the web app).

2. DBCP is built into Tomcat so you don't need to install a JAR for that.

3. The <Resource> tag goes inside the <Context> tag for the web app,
wherever it is (server.xml, webapps/<app>/META-INF/context.xml or
conf/Catalina/localhost/<app>.xml)
Note that the syntax for <Resource> has changed from earlier versions
– see the Tomcat documentation. Here's a sample:

<Resource name="jdbc/???"
    type="javax.sql.DataSource"
    auth="Container"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/???"
    username="???"
    password="???"
    maxIdle="15"
    maxActive="50"
    maxWait="10000"
    factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
    removeAbandoned="true"
    removeAbandonedTimeout="60"
    logAbandoned="true"/>

The "???" bits are installation-dependent. Some of the parameters will
be different for Sybase (driverClassName and url for sure).

4. Yes, it is supposed to say "... .dbcp.dbcp ..." in the factory= line.

5. The code to get a DB connection is:
    InitialContext initCtx = new InitialContext();
    DataSource ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/???");
    Connection conn = ds.getConnection();
Make sure that "jdbc/???" is the same here as in the <Resource> tag.

6. Always close the connection when you're done with it. Use a
"finally" block to make sure.

7. If you're trying to decide where to put the <Context> declaration,
the choices are:
- server.xml – Don't put it here. We're told it's bad.
- webapps/<app>/META-INF/context.xml – If you put it here, it will be
bundled up in the app's WAR file. That makes it easier to install, but
harder to configure if every installation has different details for
the database <Resource> tag.
- conf/Catalina/localhost/<app>.xml – If you put it here, it's easier
to edit the <Resource> tag, but it's an extra file to be installed in
addition to the WAR.

Hope this helps. At least it's shorter than
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html.
:-)

On 1/19/06, g m <[EMAIL PROTECTED]> wrote:
> There seems to be 'truckloads' of information on just as many forums on how 
> best to setup a JDBC connection pool, varying from which file to put what 
> entries (server.xml, context.xml, web.xml) etc....
>
>   It looks like the same questions be asked in a slightly different fashion 
> and for different environments.
>
>   Does anyone happen to know where there is a definative guide on how to do 
> this and what jar files one needs ?... or does this sort of 'clean doc'  not 
> exist ?
>
>   FYI: My environment: Tomcat 5.5.9, Sybase, Windows .
>   Many thanks!

--
Len

Reply via email to