Have used this for MySQL DB - am NOT totally sure that it is completely
correct

This is what works for me - (see NOTES at end - if anyone can shed any light
on Limiting Pool size)

#1    in your Server.xml
<GlobalNamingResources>
    <Resource name="MySQLDataSourceFactory"
type="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource"
auth="Container"/>
    <ResourceParams name="MySQLDataSourceFactory">
        <parameter>
            <name>factory</name>

<value>com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory</value>
        </parameter>
        <parameter>
            <name>port</name>
            <value>3306</value>
        </parameter>
        <parameter>
            <name>user</name>
            <value>dbUsername</value>
        </parameter>
        <parameter>
            <name>password</name>
            <value>dbUserPassword</value>
        </parameter>
        <parameter>
            <name>serverName</name>
            <value>dbHostIP_Name</value>
        </parameter>
        <parameter>
            <name>databaseName</name>
            <value>dbName</value>
        </parameter>
    </ResourceParams>
.....
</GlobalNamingResources>

#2    in your Context section (either in its own context fragment file or
Context section of server.xml)
<Context
    className="org.apache.catalina.core.StandardContext"
    backgroundProcessorDelay="-1"
    cachingAllowed="true"
    charsetMapperClass="org.apache.catalina.util.CharsetMapper"
    configFile="......\Catalina\localhost\yourContextFragment.xml"     *****
NOT req'd if your Context is defined in server.xml
    cookies="true"
    crossContext="false"
    debug="9"
    displayName="Your webApp name to be displayed in webApp manager"
    docBase="....../yourWebApp.war"
***** NOT req'd if deploying via Tomcat WebApp manager - see NOTEs below
    domain="Catalina"
    engineName="Catalina"
    j2EEApplication="none"
    j2EEServer="none"
    lazy="true"
    managerChecksFrequency="6"
    path="/yourWebAppContextPath"
    privileged="false"
    reloadable="false"
    startupTime="47"
    swallowOutput="false"
    tldScanTime="875"
    useNaming="true"
    wrapperClass="org.apache.catalina.core.StandardWrapper">
    <ResourceLink
        global="MySQLDataSourceFactory"                     ****    the JNDI
name as defined in GlobalNamingResources|Resource
        name="jdbc/yourJNDIResourceDBName"             ****    the JNDI name
as used in your webApp code - see below
        type="javax.sql.DataSource"/>
</Context>

#3    you can test this with the following code fragment
    System.out.println("Getting Context info");
    Context initCtx = new InitialContext();
    System.out.println("Got Initial Context");
    Context envCtx = (Context)initCtx.lookup("java:comp/env");
    System.out.println("Got JWSDP Environment Context");
    try{
        System.out.println("Getting MySQL DataSource");
        DataSource ds =
(DataSource)envCtx.lookup("jdbc/yourJNDIResourceDBName");
        if(ds != null)
        {
            System.out.println("Got MySQL DataSource");
            Vector vConns = new Vector();
            try{
                for(int i = 0; i < SOMEREASONABLYLARGENUMBER; i++)
                {
                    vConns.add(ds.getConnection());
                    System.out.println("Got MySQL DB Connection '" + i + "'
from Pool");
                }
            }catch(Exception eX){
                eX.printStackTrace();
            }finally{
                //*************    Don't forget to release the DB
Connections    **********
                Iterator iT = vConns.iterator();
                while(iT.hasNext())
                {
                    Connection conn = (Connection)iT.next();
                    conn.close();
                }
            }
        }
        else
            System.out.println("NULL MySQL DataSource");
    }catch(Exception eX){
        eX.printStackTrace();
    }


NOTEs
1     you do NOT need a <resource-ref> entry in you web.xml -
            the <ResourceLink ..../> in your Context definition is an
alternative mechanism & provides the JNDI name translation from your webApp
world to the                     GLOBAL name in the Container world
2    Tomcat WebAdmin tool does NOT show this connection pool in
Resource|Data Sources (so don't waste time looking for it)
3    Apparently you can build the Context fragment into the WAR file (will
check this next as it means you can have a self contained webApp that you
can deploy easily via Tomcat Web Manager without Stopping/starting Tomcat
all the time)
4    Make sure the MySQL jar file
(mysql-connector-java-3.0.10-stable-bin.jar) is in
...Tomact_Install_Dir\common\lib
5    using the jdbc prefix to yourJNDIResourceDBName is just a CONVENTION -
you don'y have to comply with it


Hope this is of use
Any comments/corrections please post a reply

Stefan




"Mike Duffy" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> The reference book I have shows how to configure a data resource (JDBC) in
the server.xml.
>
> Does anyone have a reference on how to do this in the web.xml?
>
> I'd like to be able to unpack a war and have everything run, without the
need to edit the
> server.xml.
>
> Thanks for your help.
>
> Mike
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Finance: Get your refund fast by filing online.
> http://taxes.yahoo.com/filing.html




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to