You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mike Duffy <md...@yahoo.com> on 2004/02/15 23:58:54 UTC

Configuring a Data Resource in web.xml

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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Configuring a Data Resource in web.xml

Posted by Jose Alfonso Martinez <tr...@linuxcenter.com.mx>.
I don't think you can. 

In web.xml you only make the named DataSource available for your webapp, but the DataSource must be setted up already (in server.xml)...

Therefore, I think there is no possible way to do it. Does anyone know a solution, I will be interested to know it too!

Jose

On Sun, Feb 15, 2004 at 02:58:54PM -0800, Mike Duffy wrote:
> 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: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 

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


Re: Configuring a Data Resource in web.xml

Posted by SMaric <sm...@ntlworld.com>.
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" <md...@yahoo.com> wrote in message
news:20040215225854.27202.qmail@web14913.mail.yahoo.com...
> 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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Tomcat 5 and IIS 5

Posted by Julien Martin <ju...@wanadoo.fr>.
Hello,
I know this question must have been asked before. All I want is the location
of the documentation about hooking up Tomcat 5.0 with IIS 5. Note that when
you click on the "jk documentation" link on the following page:
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/index.html You are
redirected to the download page of Jakarta.
So where is the documentation?
Thanks in advance,
Julien Martin.


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


Re: Configuring a Data Resource in web.xml

Posted by Harry Mantheakis <ha...@mantheakis.freeserve.co.uk>.
> Well, get ready to start standing....

I knew about the bit that goes in the deployment descriptor (!) It was 'the
rest' I was referring to :-)


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


Re: Configuring a Data Resource in web.xml

Posted by Jacob Kjome <ho...@visi.com>.
At 10:16 AM 2/16/2004 +0000, you wrote:
>I not think you can put the JNDI/Resource stuff in the deployment
>descriptor, though I stand to be corrected (!)

Well, get ready to start standing....


   <resource-ref>
       <description>DB Connection</description>
       <res-ref-name>jdbc/TestDB</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
   </resource-ref>

That goes in your web.xml.  Of course, you are right about the rest.   You 
need to provide the configuration for the jdbc/TestDB Datasource....

http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html

Jake


>AFAIK the JNDI/Resource stuff is placed within an application's 'Context'
>element.
>
>With Tomcat 5 you can have separate context fragments - individual XML
>documents - for each application.
>
>Context fragments are cool because you can update them without having to
>touch the server's configuration file (server.xml).
>
>Context fragments reside in $CATALINA_HOME/conf/Catalina/<host> directory
>where <host> is the name of the relevant host specified in server.xml. The
>default host setting is 'localhost'.
>
>I hope that helps!
>
>Harry Mantheakis
>London, UK
>
>
>
> > 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: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


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


Re: Tomcat 5.0 Not Displaying the Stack Trace

Posted by Remy Maucherat <re...@jboss.org>.
Mike Duffy wrote:

> I just switched to Tomcat 5.0.
> 
> For some reason the stack trace is not displayed when an error is generated (the error is in the
> log); a blank page is displayed.
> 
> Any suggestions?

This works for me. So what is the actual exception ?

-- 
xxxxxxxxxxxxxxxxxxxxxxxxx
Rémy Maucherat
Developer & Consultant
JBoss Group (Europe) SàRL
xxxxxxxxxxxxxxxxxxxxxxxxx

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


Tomcat 5.0 Not Displaying the Stack Trace

Posted by Mike Duffy <md...@yahoo.com>.
I just switched to Tomcat 5.0.

For some reason the stack trace is not displayed when an error is generated (the error is in the
log); a blank page is displayed.

Any suggestions?

Thanks.

Mike

__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

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


Re: Configuring a Data Resource in web.xml

Posted by Harry Mantheakis <ha...@mantheakis.freeserve.co.uk>.
I not think you can put the JNDI/Resource stuff in the deployment
descriptor, though I stand to be corrected (!)

AFAIK the JNDI/Resource stuff is placed within an application's 'Context'
element.

With Tomcat 5 you can have separate context fragments - individual XML
documents - for each application.

Context fragments are cool because you can update them without having to
touch the server's configuration file (server.xml).

Context fragments reside in $CATALINA_HOME/conf/Catalina/<host> directory
where <host> is the name of the relevant host specified in server.xml. The
default host setting is 'localhost'.

I hope that helps!

Harry Mantheakis
London, UK



> 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: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 


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