You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Nhut Thai Le <ln...@yahoo.com> on 2007/07/07 16:20:10 UTC

How to use connection pool with tomcat 1.2.9

Hi guys,
  I 'm developing a simple web app with netbeans with bundle tomcat 1.2.9. I want to use connection pooling fir my web app. Thus, i config as follow:
   
  Here is my server.xml:
<Server port="8005" shutdown="SHUTDOWN">
    <Listener className="org.apache.catalina.core.AprLifecycleListener" />
    <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
    <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
    <GlobalNamingResources>
        <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
        <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" />        
    </GlobalNamingResources>
    <Service name="Catalina">
        <Connector port="8080" maxHttpHeaderSize="8192"
                   maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="false" redirectPort="8443" acceptCount="100"
                   connectionTimeout="20000" disableUploadTimeout="true" />
        <Connector port="8009" 
                   enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
        <Engine name="Catalina" defaultHost="localhost">
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                   resourceName="UserDatabase"/>
            <Host name="localhost" appBase="webapps"
                  unpackWARs="true" autoDeploy="true"
                  xmlValidation="false" xmlNamespaceAware="false">
                <Context path="/Core1" docBase="Core1" debug="5" reloadable="true" crossContext="true">
                    <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
                              maxActive="100" maxIdle="30" maxWait="10000"
                              username="me" password="iam" driverClassName="com.mysql.jdbc.Driver"
                              url="jdbc:mysql://localhost/mydb?autoReconnect=true"/>                    
                </Context>                
            </Host>            
        </Engine>        
    </Service>    
</Server>
  
And here is my WEB-INF/web.xml

  <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <filter>
        <filter-name>AccessControl</filter-name>
        <filter-class>com.core1.filter.AccessControl</filter-class>
<init-param>
   <param-name>loginPage</param-name>
   <param-value>/WEB-INF/authentication/login.jsp</param-value>
</init-param>
    </filter>
    <filter-mapping>
        <filter-name>AccessControl</filter-name>
        <url-pattern>/protected/*</url-pattern>
    </filter-mapping>
    <listener>
       <listener-class>com.core1.listener.ResourceManagerListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <init-param>
            <param-name>debug</param-name>
            <param-value>2</param-value>
        </init-param>
        <init-param>
            <param-name>detail</param-name>
            <param-value>2</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
<welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>
    <error-page>
        <exception-type>Exception</exception-type>
        <location>/WEB-INF/error/error.jsp</location>
    </error-page>
    <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>
</web-app>
  
I assume that by referencing the DataSource in WEB-INF/web.xml to the DataSource initialized in server.xml, I can access the Datasource from anywhere. However, in one of my Action Class(i'm using Struts framework) I have the following code
   
  DataSource ds = this.getDataSource(request,"jdbc/TestDB");
if(ds == null)
    throw new InternalException("datasource is null");
  
Supprisingly, the exception is thrown! The DataSource is null after all.Is there anything else i have to do? It's been 2 weeks i have stuck with this problem. Hope anyone can give a suggestion
   
  Thai


-------------------------
Where there's will, there's a way
 
---------------------------------
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.

Re: How to use connection pool with tomcat 1.2.9

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thai,

Nhut Thai Le wrote:
> Thanks for the info about the struts 1.3. If you didnt say that, i 
> would pack everything up and deploy on a school server for my demo 
> next week. So now I gotta change back to container-managed 
> dataSource.

You can still do your demo. Just make sure that you eventually convert
your configuration, or you'll be stuck on that old version of Struts.

> As I said, i did declare the tomcat dataSource in server.xml and
> WEB-INF/web.xml.

Don't do that. Since you're using Tomcat 5.5, you should declare your
DataSource in META-INF/context.xml, along with your Realm. Then, you
don't ever have to touch server.xml, which is nice.

> As you said, i should write a class which extend the struts Action
> class  then overwrite the getDatasource() method in such a way that
> it gonna return the datasource that i have declared in server.xml and
> web.xml, but how can i access the container-managed datasource from
> my custom action class?

The same way you should be accessing a JNDI DataSource from anywhere:

import javax.naming.*;
import java.sql.Connection;
...
String DATASOURCE = "jdbc/TestDB";
String DATASOURCE_PATH = "java:/comp/env/" + DATASOURCE;
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(DATASOURCE_PATH);
Connection conn = dx.getConnection();

Of course, you'll need some error checking, etc.

> url="jdbc:mysql://localhost/core?autoReconnect=true"/>

Oh, get rid of "autoReconnect", too. See the Connector/J documentation
for why you shouldn't use it.

See the documentation reference that Davis posted, too. It should lay
everything out for you, if I haven't done so already.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGk5BW9CaO5/Lv0PARArxmAJ9F6HDH8UQE7voQhBp4fOEsClyANACcC6tE
FbPk6hTJ0tcPY6OgBRwgbOs=
=2Vfq
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to use connection pool with tomcat 1.2.9

Posted by David Smith <dn...@cornell.edu>.
There are configuration and coding examples on the tomcat website at

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

Take a look at that and post a follow up if you still have questions.

--David

Nhut Thai Le wrote:
> Hi Chris,
>   Thanks for the info about the struts 1.3. If you didnt say that, i would pack everything up and deploy on a school server for my demo next week. So now I gotta change back to container-managed dataSource. As I said, i did declare the tomcat dataSource in server.xml and WEB-INF/web.xml. As you said, i should write a class which extend the struts Action class  then overwrite the getDatasource() method in such a way that it gonna return the datasource that i have declared in server.xml and web.xml, but how can i access the container-managed datasource from my custom action class?
>   My server.xml has:
>   <Host name="localhost" appBase="webapps"
>                   unpackWARs="true" autoDeploy="true"
>                   xmlValidation="false" xmlNamespaceAware="false">
>   <Context path="/Core1" docBase="Core1" debug="5" 
>                 reloadable="true" crossContext="true">
>           <Resource name="jdbc/TestDB" auth="Container" 
>                            type="javax.sql.DataSource"
>                          maxActive="100" maxIdle="30" maxWait="10000"
>                          username="myname" password="mypass"
>                            driverClassName="com.mysql.jdbc.Driver"
>                          url="jdbc:mysql://localhost/core?autoReconnect=true"/>
>                     
>  </Context>
>   </Host>
>   And my WEB-INF/web.xml is
>   <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>
>   Hope you can give some suggestion
>   Thanks in advance
>   Thai
>  
> Christopher Schultz <ch...@christopherschultz.net> wrote:
>   -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Thai,
>
> Nhut Thai Le wrote:
>   
>> Servlet decument says: getDatasource(HTTPServletRequest) is used to 
>> get the default datasource, getDataSource(HttpServletRequest, String)
>> get the selected datasource.
>>     
>
> This appears to be a Struts method, not anything from the servlet
> specification. You need to be very specific when you quote things like
> this.
> http://struts.apache.org/1.2.9/api/org/apache/struts/action/Action.html#getDataSource(javax.servlet.http.HttpServletRequest)
>
>   
>> However, since I am using struts. following instruction in tomcat
>> documentation on connection pooling and using getDatasource within a
>> struts action class give a null resource because although action
>> class has getDatasource(HttpServletRequest) as the httpServlet class,
>> it only return resource which is managed by strut not the from
>> container as the httpServlet object does.
>>     
>
> Exactly. If you are using Tomcat-managed DataSources, you cannot use
> Struts's Action.getDataSource method. You will have to write your own.
> If you have a base action from which all your existing actions extend,
> you can simply override getDataSource and implement it correctly for a
> JNDI-based DataSource.
>
> Better yet, separate your database queries from your Struts actions, and
> forget Action.getDataSource ever existed.
>
>   
>> I'm now letting struts manages the resource. My problem is partly
>> solved for now.
>>     
>
> You should NOT do this. Struts has abandoned DataSource management as of
> version 1.3 in favor of container-managed DataSources (as it should have
> been all along). You should get Tomcat-based DataSource management
> working. We will help you, though I'm guessing that this thread is over
> and nobody will read this follow-up. :(
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGklYb9CaO5/Lv0PARAmWpAJ9TJ+97VfAs5PrE0C240355BixskQCgrdmY
> kZK5rfPcUHqyi8bzgjTMrDg=
> =Vjnk
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>
> -------------------------
> Where there's will, there's a way
>        
> ---------------------------------
> Luggage? GPS? Comic books? 
> Check out fitting  gifts for grads at Yahoo! Search.
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to use connection pool with tomcat 1.2.9

Posted by Nhut Thai Le <ln...@yahoo.com>.
Hi Chris,
  Thanks for the info about the struts 1.3. If you didnt say that, i would pack everything up and deploy on a school server for my demo next week. So now I gotta change back to container-managed dataSource. As I said, i did declare the tomcat dataSource in server.xml and WEB-INF/web.xml. As you said, i should write a class which extend the struts Action class  then overwrite the getDatasource() method in such a way that it gonna return the datasource that i have declared in server.xml and web.xml, but how can i access the container-managed datasource from my custom action class?
  My server.xml has:
  <Host name="localhost" appBase="webapps"
                  unpackWARs="true" autoDeploy="true"
                  xmlValidation="false" xmlNamespaceAware="false">
  <Context path="/Core1" docBase="Core1" debug="5" 
                reloadable="true" crossContext="true">
          <Resource name="jdbc/TestDB" auth="Container" 
                           type="javax.sql.DataSource"
                         maxActive="100" maxIdle="30" maxWait="10000"
                         username="myname" password="mypass"
                           driverClassName="com.mysql.jdbc.Driver"
                         url="jdbc:mysql://localhost/core?autoReconnect=true"/>
                    
 </Context>
  </Host>
  And my WEB-INF/web.xml is
  <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>
  Hope you can give some suggestion
  Thanks in advance
  Thai
 
Christopher Schultz <ch...@christopherschultz.net> wrote:
  -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thai,

Nhut Thai Le wrote:
> Servlet decument says: getDatasource(HTTPServletRequest) is used to 
> get the default datasource, getDataSource(HttpServletRequest, String)
> get the selected datasource.

This appears to be a Struts method, not anything from the servlet
specification. You need to be very specific when you quote things like
this.
http://struts.apache.org/1.2.9/api/org/apache/struts/action/Action.html#getDataSource(javax.servlet.http.HttpServletRequest)

> However, since I am using struts. following instruction in tomcat
> documentation on connection pooling and using getDatasource within a
> struts action class give a null resource because although action
> class has getDatasource(HttpServletRequest) as the httpServlet class,
> it only return resource which is managed by strut not the from
> container as the httpServlet object does.

Exactly. If you are using Tomcat-managed DataSources, you cannot use
Struts's Action.getDataSource method. You will have to write your own.
If you have a base action from which all your existing actions extend,
you can simply override getDataSource and implement it correctly for a
JNDI-based DataSource.

Better yet, separate your database queries from your Struts actions, and
forget Action.getDataSource ever existed.

> I'm now letting struts manages the resource. My problem is partly
> solved for now.

You should NOT do this. Struts has abandoned DataSource management as of
version 1.3 in favor of container-managed DataSources (as it should have
been all along). You should get Tomcat-based DataSource management
working. We will help you, though I'm guessing that this thread is over
and nobody will read this follow-up. :(

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGklYb9CaO5/Lv0PARAmWpAJ9TJ+97VfAs5PrE0C240355BixskQCgrdmY
kZK5rfPcUHqyi8bzgjTMrDg=
=Vjnk
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org




-------------------------
Where there's will, there's a way
       
---------------------------------
Luggage? GPS? Comic books? 
Check out fitting  gifts for grads at Yahoo! Search.

Re: How to use connection pool with tomcat 1.2.9

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thai,

Nhut Thai Le wrote:
> Servlet decument says: getDatasource(HTTPServletRequest) is used to 
> get the default datasource, getDataSource(HttpServletRequest, String)
> get the selected datasource.

This appears to be a Struts method, not anything from the servlet
specification. You need to be very specific when you quote things like
this.
http://struts.apache.org/1.2.9/api/org/apache/struts/action/Action.html#getDataSource(javax.servlet.http.HttpServletRequest)

> However, since I am using struts. following instruction in tomcat
> documentation on connection pooling and using getDatasource within a
> struts action class give a null resource because although action
> class has getDatasource(HttpServletRequest) as the httpServlet class,
> it only return resource which is managed by strut not the from
> container as the httpServlet object does.

Exactly. If you are using Tomcat-managed DataSources, you cannot use
Struts's Action.getDataSource method. You will have to write your own.
If you have a base action from which all your existing actions extend,
you can simply override getDataSource and implement it correctly for a
JNDI-based DataSource.

Better yet, separate your database queries from your Struts actions, and
forget Action.getDataSource ever existed.

> I'm now letting struts manages the resource. My problem is partly
> solved for now.

You should NOT do this. Struts has abandoned DataSource management as of
version 1.3 in favor of container-managed DataSources (as it should have
been all along). You should get Tomcat-based DataSource management
working. We will help you, though I'm guessing that this thread is over
and nobody will read this follow-up. :(

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGklYb9CaO5/Lv0PARAmWpAJ9TJ+97VfAs5PrE0C240355BixskQCgrdmY
kZK5rfPcUHqyi8bzgjTMrDg=
=Vjnk
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to use connection pool with tomcat 1.2.9

Posted by Nhut Thai Le <ln...@yahoo.com>.
Servlet decument says: getDatasource(HTTPServletRequest) is used to get the default datasource, getDataSource(HttpServletRequest, String) get the selected datasource. However, since I am using struts. following instruction in tomcat documentation on connection pooling and using getDatasource within a struts action class give a null resource because although action class has getDatasource(HttpServletRequest) as the httpServlet class, it only return resource which is managed by strut not the from container as the httpServlet object does.
I'm now letting struts manages the resource. My problem is partly solved for now.
Thanks for your suggestion
Thai
David Smith <dn...@cornell.edu> wrote: Not knowing how this code is working:

  DataSource ds = this.getDataSource(request,"jdbc/TestDB");
 > if(ds == null)
 >     throw new InternalException("datasource is null");

I'm not sure what to tell you.  The method getDataSource( request, 
"jdbc/TestDB" ) is not a part of tomcat or the servlet spec.  Is it part 
of Struts?

--David

Nhut Thai Le wrote:
> You are definitely right, i was sleepy while posting the question. The 1.2.9 is the struts version. The bundles tomcat is 5.5.17. But is it the cause of my problem? 
>
> David Smith  wrote: Tomcat 1.2.9???  I doubt that's the real version number.  Typical 
> version numbers are 4.x, 5.0.x, 5.5.x, or 6.0.x.  I think Netbeans 
> bundles started with 5.0.x later upgraded to 5.5.x with Netbeans 5.5.  
> Could you take another look?
>
> --David
>
> Nhut Thai Le wrote:
>   
>> Hi guys,
>>   I 'm developing a simple web app with netbeans with bundle tomcat 1.2.9. I want to use connection pooling fir my web app. Thus, i config as follow:
>>    
>>   Here is my server.xml:
>>
>>   
>> And here is my WEB-INF/web.xml
>>
>>   
>>
>>     
>>         AccessControl
>>         com.core1.filter.AccessControl
>>
>>    
>>     
> loginPage
>
>   
>>    
>>     
> /WEB-INF/authentication/login.jsp
>
>   
>>     
>>     
>>         AccessControl
>>         /protected/*
>>     
>>     
>>     
>
>   
>>        
>>     
> com.core1.listener.ResourceManagerListener
>   
>>     
>>     
>>         action
>>         org.apache.struts.action.ActionServlet
>>         
>>             
>>     
> config
>
>   
>>             
>>     
> /WEB-INF/struts-config.xml
>
>   
>>         
>>         
>>             
>>     
> debug
>
>   
>>             
>>     
> 2
>
>   
>>         
>>         
>>             
>>     
> detail
>
>   
>>             
>>     
> 2
>
>   
>>         
>>         2
>>     
>>     
>>         action
>>         *.do
>>     
>>     
>>         
>>             30
>>         
>>     
>>     
>>
>>             index.jsp
>>         
>>     
>>     
>>         Exception
>>         /WEB-INF/error/error.jsp
>>     
>>     
>>         DB connection
>>         jdbc/TestDB
>>         javax.sql.DataSource
>>         Container
>>     
>>
>>   
>> I assume that by referencing the DataSource in WEB-INF/web.xml to the DataSource initialized in server.xml, I can access the Datasource from anywhere. However, in one of my Action Class(i'm using Struts framework) I have the following code
>>    
>>   DataSource ds = this.getDataSource(request,"jdbc/TestDB");
>> if(ds == null)
>>     throw new InternalException("datasource is null");
>>   
>> Supprisingly, the exception is thrown! The DataSource is null after all.Is there anything else i have to do? It's been 2 weeks i have stuck with this problem. Hope anyone can give a suggestion
>>    
>>   Thai
>>
>>
>> -------------------------
>> Where there's will, there's a way
>>  
>> ---------------------------------
>> We won't tell. Get more on shows you hate to love
>> (and love to hate): Yahoo! TV's Guilty Pleasures list.
>>   
>>     
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>
> -------------------------
> Where there's will, there's a way
>        
> ---------------------------------
> Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org




-------------------------
Where there's will, there's a way
       
---------------------------------
Boardwalk for $500? In 2007? Ha! 
Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.

Re: How to use connection pool with tomcat 1.2.9

Posted by David Smith <dn...@cornell.edu>.
Not knowing how this code is working:

  DataSource ds = this.getDataSource(request,"jdbc/TestDB");
 > if(ds == null)
 >     throw new InternalException("datasource is null");

I'm not sure what to tell you.  The method getDataSource( request, 
"jdbc/TestDB" ) is not a part of tomcat or the servlet spec.  Is it part 
of Struts?

--David

Nhut Thai Le wrote:
> You are definitely right, i was sleepy while posting the question. The 1.2.9 is the struts version. The bundles tomcat is 5.5.17. But is it the cause of my problem? 
>
> David Smith <dn...@cornell.edu> wrote: Tomcat 1.2.9???  I doubt that's the real version number.  Typical 
> version numbers are 4.x, 5.0.x, 5.5.x, or 6.0.x.  I think Netbeans 
> bundles started with 5.0.x later upgraded to 5.5.x with Netbeans 5.5.  
> Could you take another look?
>
> --David
>
> Nhut Thai Le wrote:
>   
>> Hi guys,
>>   I 'm developing a simple web app with netbeans with bundle tomcat 1.2.9. I want to use connection pooling fir my web app. Thus, i config as follow:
>>    
>>   Here is my server.xml:
>>
>>   
>> And here is my WEB-INF/web.xml
>>
>>   
>>
>>     
>>         AccessControl
>>         com.core1.filter.AccessControl
>>
>>    
>>     
> loginPage
>
>   
>>    
>>     
> /WEB-INF/authentication/login.jsp
>
>   
>>     
>>     
>>         AccessControl
>>         /protected/*
>>     
>>     
>>     
>
>   
>>        
>>     
> com.core1.listener.ResourceManagerListener
>   
>>     
>>     
>>         action
>>         org.apache.struts.action.ActionServlet
>>         
>>             
>>     
> config
>
>   
>>             
>>     
> /WEB-INF/struts-config.xml
>
>   
>>         
>>         
>>             
>>     
> debug
>
>   
>>             
>>     
> 2
>
>   
>>         
>>         
>>             
>>     
> detail
>
>   
>>             
>>     
> 2
>
>   
>>         
>>         2
>>     
>>     
>>         action
>>         *.do
>>     
>>     
>>         
>>             30
>>         
>>     
>>     
>>
>>             index.jsp
>>         
>>     
>>     
>>         Exception
>>         /WEB-INF/error/error.jsp
>>     
>>     
>>         DB connection
>>         jdbc/TestDB
>>         javax.sql.DataSource
>>         Container
>>     
>>
>>   
>> I assume that by referencing the DataSource in WEB-INF/web.xml to the DataSource initialized in server.xml, I can access the Datasource from anywhere. However, in one of my Action Class(i'm using Struts framework) I have the following code
>>    
>>   DataSource ds = this.getDataSource(request,"jdbc/TestDB");
>> if(ds == null)
>>     throw new InternalException("datasource is null");
>>   
>> Supprisingly, the exception is thrown! The DataSource is null after all.Is there anything else i have to do? It's been 2 weeks i have stuck with this problem. Hope anyone can give a suggestion
>>    
>>   Thai
>>
>>
>> -------------------------
>> Where there's will, there's a way
>>  
>> ---------------------------------
>> We won't tell. Get more on shows you hate to love
>> (and love to hate): Yahoo! TV's Guilty Pleasures list.
>>   
>>     
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>
> -------------------------
> Where there's will, there's a way
>        
> ---------------------------------
> Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to use connection pool with tomcat 1.2.9

Posted by Nhut Thai Le <ln...@yahoo.com>.
You are definitely right, i was sleepy while posting the question. The 1.2.9 is the struts version. The bundles tomcat is 5.5.17. But is it the cause of my problem? 

David Smith <dn...@cornell.edu> wrote: Tomcat 1.2.9???  I doubt that's the real version number.  Typical 
version numbers are 4.x, 5.0.x, 5.5.x, or 6.0.x.  I think Netbeans 
bundles started with 5.0.x later upgraded to 5.5.x with Netbeans 5.5.  
Could you take another look?

--David

Nhut Thai Le wrote:
> Hi guys,
>   I 'm developing a simple web app with netbeans with bundle tomcat 1.2.9. I want to use connection pooling fir my web app. Thus, i config as follow:
>    
>   Here is my server.xml:
> 
>   
> And here is my WEB-INF/web.xml
>
>   
> 
>     
>         AccessControl
>         com.core1.filter.AccessControl
> 
>    
loginPage

>    
/WEB-INF/authentication/login.jsp

> 
>     
>     
>         AccessControl
>         /protected/*
>     
>     

>        
com.core1.listener.ResourceManagerListener
>     
>     
>         action
>         org.apache.struts.action.ActionServlet
>         
>             
config

>             
/WEB-INF/struts-config.xml

>         
>         
>             
debug

>             
2

>         
>         
>             
detail

>             
2

>         
>         2
>     
>     
>         action
>         *.do
>     
>     
>         
>             30
>         
>     
>     
> 
>             index.jsp
>         
>     
>     
>         Exception
>         /WEB-INF/error/error.jsp
>     
>     
>         DB connection
>         jdbc/TestDB
>         javax.sql.DataSource
>         Container
>     
> 
>   
> I assume that by referencing the DataSource in WEB-INF/web.xml to the DataSource initialized in server.xml, I can access the Datasource from anywhere. However, in one of my Action Class(i'm using Struts framework) I have the following code
>    
>   DataSource ds = this.getDataSource(request,"jdbc/TestDB");
> if(ds == null)
>     throw new InternalException("datasource is null");
>   
> Supprisingly, the exception is thrown! The DataSource is null after all.Is there anything else i have to do? It's been 2 weeks i have stuck with this problem. Hope anyone can give a suggestion
>    
>   Thai
>
>
> -------------------------
> Where there's will, there's a way
>  
> ---------------------------------
> We won't tell. Get more on shows you hate to love
> (and love to hate): Yahoo! TV's Guilty Pleasures list.
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org




-------------------------
Where there's will, there's a way
       
---------------------------------
Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.

Re: How to use connection pool with tomcat 1.2.9

Posted by David Smith <dn...@cornell.edu>.
Tomcat 1.2.9???  I doubt that's the real version number.  Typical 
version numbers are 4.x, 5.0.x, 5.5.x, or 6.0.x.  I think Netbeans 
bundles started with 5.0.x later upgraded to 5.5.x with Netbeans 5.5.  
Could you take another look?

--David

Nhut Thai Le wrote:
> Hi guys,
>   I 'm developing a simple web app with netbeans with bundle tomcat 1.2.9. I want to use connection pooling fir my web app. Thus, i config as follow:
>    
>   Here is my server.xml:
> <Server port="8005" shutdown="SHUTDOWN">
>     <Listener className="org.apache.catalina.core.AprLifecycleListener" />
>     <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
>     <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
>     <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
>     <GlobalNamingResources>
>         <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
>         <Resource name="UserDatabase" auth="Container"
>                   type="org.apache.catalina.UserDatabase"
>                   description="User database that can be updated and saved"
>                   factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
>                   pathname="conf/tomcat-users.xml" />        
>     </GlobalNamingResources>
>     <Service name="Catalina">
>         <Connector port="8080" maxHttpHeaderSize="8192"
>                    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
>                    enableLookups="false" redirectPort="8443" acceptCount="100"
>                    connectionTimeout="20000" disableUploadTimeout="true" />
>         <Connector port="8009" 
>                    enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
>         <Engine name="Catalina" defaultHost="localhost">
>             <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
>                    resourceName="UserDatabase"/>
>             <Host name="localhost" appBase="webapps"
>                   unpackWARs="true" autoDeploy="true"
>                   xmlValidation="false" xmlNamespaceAware="false">
>                 <Context path="/Core1" docBase="Core1" debug="5" reloadable="true" crossContext="true">
>                     <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
>                               maxActive="100" maxIdle="30" maxWait="10000"
>                               username="me" password="iam" driverClassName="com.mysql.jdbc.Driver"
>                               url="jdbc:mysql://localhost/mydb?autoReconnect=true"/>                    
>                 </Context>                
>             </Host>            
>         </Engine>        
>     </Service>    
> </Server>
>   
> And here is my WEB-INF/web.xml
>
>   <?xml version="1.0" encoding="UTF-8"?>
> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
>     <filter>
>         <filter-name>AccessControl</filter-name>
>         <filter-class>com.core1.filter.AccessControl</filter-class>
> <init-param>
>    <param-name>loginPage</param-name>
>    <param-value>/WEB-INF/authentication/login.jsp</param-value>
> </init-param>
>     </filter>
>     <filter-mapping>
>         <filter-name>AccessControl</filter-name>
>         <url-pattern>/protected/*</url-pattern>
>     </filter-mapping>
>     <listener>
>        <listener-class>com.core1.listener.ResourceManagerListener</listener-class>
>     </listener>
>     <servlet>
>         <servlet-name>action</servlet-name>
>         <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
>         <init-param>
>             <param-name>config</param-name>
>             <param-value>/WEB-INF/struts-config.xml</param-value>
>         </init-param>
>         <init-param>
>             <param-name>debug</param-name>
>             <param-value>2</param-value>
>         </init-param>
>         <init-param>
>             <param-name>detail</param-name>
>             <param-value>2</param-value>
>         </init-param>
>         <load-on-startup>2</load-on-startup>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>action</servlet-name>
>         <url-pattern>*.do</url-pattern>
>     </servlet-mapping>
>     <session-config>
>         <session-timeout>
>             30
>         </session-timeout>
>     </session-config>
>     <welcome-file-list>
> <welcome-file>
>             index.jsp
>         </welcome-file>
>     </welcome-file-list>
>     <error-page>
>         <exception-type>Exception</exception-type>
>         <location>/WEB-INF/error/error.jsp</location>
>     </error-page>
>     <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>
> </web-app>
>   
> I assume that by referencing the DataSource in WEB-INF/web.xml to the DataSource initialized in server.xml, I can access the Datasource from anywhere. However, in one of my Action Class(i'm using Struts framework) I have the following code
>    
>   DataSource ds = this.getDataSource(request,"jdbc/TestDB");
> if(ds == null)
>     throw new InternalException("datasource is null");
>   
> Supprisingly, the exception is thrown! The DataSource is null after all.Is there anything else i have to do? It's been 2 weeks i have stuck with this problem. Hope anyone can give a suggestion
>    
>   Thai
>
>
> -------------------------
> Where there's will, there's a way
>  
> ---------------------------------
> We won't tell. Get more on shows you hate to love
> (and love to hate): Yahoo! TV's Guilty Pleasures list.
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to use connection pool with tomcat 1.2.9

Posted by Nhut Thai Le <ln...@yahoo.com>.
Hi Johnny,
  The method i used is exactly what instuctructed in the 
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
Except that i dont use JSTL. However, the Datasource should be available when application started. Is there any other suggestion?
  Thai
Johnny Kewl <jo...@kewlstuff.co.za> wrote:
  
Nhut.... listen I think you mixing two different methods.....
You using a framework that works on Tomcat, and both Struts and Tomcat have 
a way of making a dB pool....
You need to choose one or the other.....
TC uses JNDI... most people I think do it this way, and it will work with or 
without struts....
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html

or do it the Struts way.... I dont use it, so no expert, but heres an 
article
http://forum.java.sun.com/thread.jspa?threadID=5146552&tstart=180

theres actually lots of other ways as well.... but these should work

good luck


----- Original Message ----- 
From: "Nhut Thai Le" 
To: 
Sent: Saturday, July 07, 2007 4:20 PM
Subject: How to use connection pool with tomcat 1.2.9


> Hi guys,
> I 'm developing a simple web app with netbeans with bundle tomcat 1.2.9. 
> I want to use connection pooling fir my web app. Thus, i config as follow:
>
> Here is my server.xml:
> 
> 

> 
> className="org.apache.catalina.mbeans.ServerLifecycleListener" />
> 
> className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
> 
> className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
> 
> > value="30"/>
> > type="org.apache.catalina.UserDatabase"
> description="User database that can be updated and saved"
> 
> factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
> pathname="conf/tomcat-users.xml" />
> 
> 
> > maxThreads="150" minSpareThreads="25" 
> maxSpareThreads="75"
> enableLookups="false" redirectPort="8443" 
> acceptCount="100"
> connectionTimeout="20000" disableUploadTimeout="true" />
> > enableLookups="false" redirectPort="8443" 
> protocol="AJP/1.3" />
> 
> > resourceName="UserDatabase"/>
> > unpackWARs="true" autoDeploy="true"
> xmlValidation="false" xmlNamespaceAware="false">
> > reloadable="true" crossContext="true">
> > type="javax.sql.DataSource"
> maxActive="100" maxIdle="30" maxWait="10000"
> username="me" password="iam" 
> driverClassName="com.mysql.jdbc.Driver"
> 
> url="jdbc:mysql://localhost/mydb?autoReconnect=true"/>
> 
> 
> 
> 
> 
>
> And here is my WEB-INF/web.xml
>
> 
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
> 
> AccessControl
> com.core1.filter.AccessControl
> 
> 
loginPage

> 
/WEB-INF/authentication/login.jsp

> 
> 
> 
> AccessControl
> /protected/*
> 
> 

> 
> 
com.core1.listener.ResourceManagerListener
> 
> 
> action
> 
> org.apache.struts.action.ActionServlet
> 
> 
config

> 
/WEB-INF/struts-config.xml

> 
> 
> 
debug

> 
2

> 
> 
> 
detail

> 
2

> 
> 2
> 
> 
> action
> *.do
> 
> 
> 
> 30
> 
> 
> 
> 
> index.jsp
> 
> 
> 
> Exception
> /WEB-INF/error/error.jsp
> 
> 
> DB connection
> jdbc/TestDB
> javax.sql.DataSource
> Container
> 
> 
>
> I assume that by referencing the DataSource in WEB-INF/web.xml to the 
> DataSource initialized in server.xml, I can access the Datasource from 
> anywhere. However, in one of my Action Class(i'm using Struts framework) I 
> have the following code
>
> DataSource ds = this.getDataSource(request,"jdbc/TestDB");
> if(ds == null)
> throw new InternalException("datasource is null");
>
> Supprisingly, the exception is thrown! The DataSource is null after all.Is 
> there anything else i have to do? It's been 2 weeks i have stuck with this 
> problem. Hope anyone can give a suggestion
>
> Thai
>
>
> -------------------------
> Where there's will, there's a way
>
> ---------------------------------
> We won't tell. Get more on shows you hate to love
> (and love to hate): Yahoo! TV's Guilty Pleasures list. 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org




-------------------------
Where there's will, there's a way
 
---------------------------------
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.

Re: How to use connection pool with tomcat 1.2.9

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Nhut.... listen I think you mixing two different methods.....
You using a framework that works on Tomcat, and both Struts and Tomcat have 
a way of making a dB pool....
You need to choose one or the other.....
TC uses JNDI... most people I think do it this way, and it will work with or 
without struts....
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html

or do it the Struts way.... I dont use it, so no expert, but heres an 
article
http://forum.java.sun.com/thread.jspa?threadID=5146552&tstart=180

theres actually lots of other ways as well.... but these should work

good luck


----- Original Message ----- 
From: "Nhut Thai Le" <ln...@yahoo.com>
To: <us...@tomcat.apache.org>
Sent: Saturday, July 07, 2007 4:20 PM
Subject: How to use connection pool with tomcat 1.2.9


> Hi guys,
>  I 'm developing a simple web app with netbeans with bundle tomcat 1.2.9. 
> I want to use connection pooling fir my web app. Thus, i config as follow:
>
>  Here is my server.xml:
> <Server port="8005" shutdown="SHUTDOWN">
>    <Listener className="org.apache.catalina.core.AprLifecycleListener" />
>    <Listener 
> className="org.apache.catalina.mbeans.ServerLifecycleListener" />
>    <Listener 
> className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
>    <Listener 
> className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
>    <GlobalNamingResources>
>        <Environment name="simpleValue" type="java.lang.Integer" 
> value="30"/>
>        <Resource name="UserDatabase" auth="Container"
>                  type="org.apache.catalina.UserDatabase"
>                  description="User database that can be updated and saved"
> 
> factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
>                  pathname="conf/tomcat-users.xml" />
>    </GlobalNamingResources>
>    <Service name="Catalina">
>        <Connector port="8080" maxHttpHeaderSize="8192"
>                   maxThreads="150" minSpareThreads="25" 
> maxSpareThreads="75"
>                   enableLookups="false" redirectPort="8443" 
> acceptCount="100"
>                   connectionTimeout="20000" disableUploadTimeout="true" />
>        <Connector port="8009"
>                   enableLookups="false" redirectPort="8443" 
> protocol="AJP/1.3" />
>        <Engine name="Catalina" defaultHost="localhost">
>            <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
>                   resourceName="UserDatabase"/>
>            <Host name="localhost" appBase="webapps"
>                  unpackWARs="true" autoDeploy="true"
>                  xmlValidation="false" xmlNamespaceAware="false">
>                <Context path="/Core1" docBase="Core1" debug="5" 
> reloadable="true" crossContext="true">
>                    <Resource name="jdbc/TestDB" auth="Container" 
> type="javax.sql.DataSource"
>                              maxActive="100" maxIdle="30" maxWait="10000"
>                              username="me" password="iam" 
> driverClassName="com.mysql.jdbc.Driver"
> 
> url="jdbc:mysql://localhost/mydb?autoReconnect=true"/>
>                </Context>
>            </Host>
>        </Engine>
>    </Service>
> </Server>
>
> And here is my WEB-INF/web.xml
>
>  <?xml version="1.0" encoding="UTF-8"?>
> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
>    <filter>
>        <filter-name>AccessControl</filter-name>
>        <filter-class>com.core1.filter.AccessControl</filter-class>
> <init-param>
>   <param-name>loginPage</param-name>
>   <param-value>/WEB-INF/authentication/login.jsp</param-value>
> </init-param>
>    </filter>
>    <filter-mapping>
>        <filter-name>AccessControl</filter-name>
>        <url-pattern>/protected/*</url-pattern>
>    </filter-mapping>
>    <listener>
> 
> <listener-class>com.core1.listener.ResourceManagerListener</listener-class>
>    </listener>
>    <servlet>
>        <servlet-name>action</servlet-name>
> 
> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
>        <init-param>
>            <param-name>config</param-name>
>            <param-value>/WEB-INF/struts-config.xml</param-value>
>        </init-param>
>        <init-param>
>            <param-name>debug</param-name>
>            <param-value>2</param-value>
>        </init-param>
>        <init-param>
>            <param-name>detail</param-name>
>            <param-value>2</param-value>
>        </init-param>
>        <load-on-startup>2</load-on-startup>
>    </servlet>
>    <servlet-mapping>
>        <servlet-name>action</servlet-name>
>        <url-pattern>*.do</url-pattern>
>    </servlet-mapping>
>    <session-config>
>        <session-timeout>
>            30
>        </session-timeout>
>    </session-config>
>    <welcome-file-list>
> <welcome-file>
>            index.jsp
>        </welcome-file>
>    </welcome-file-list>
>    <error-page>
>        <exception-type>Exception</exception-type>
>        <location>/WEB-INF/error/error.jsp</location>
>    </error-page>
>    <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>
> </web-app>
>
> I assume that by referencing the DataSource in WEB-INF/web.xml to the 
> DataSource initialized in server.xml, I can access the Datasource from 
> anywhere. However, in one of my Action Class(i'm using Struts framework) I 
> have the following code
>
>  DataSource ds = this.getDataSource(request,"jdbc/TestDB");
> if(ds == null)
>    throw new InternalException("datasource is null");
>
> Supprisingly, the exception is thrown! The DataSource is null after all.Is 
> there anything else i have to do? It's been 2 weeks i have stuck with this 
> problem. Hope anyone can give a suggestion
>
>  Thai
>
>
> -------------------------
> Where there's will, there's a way
>
> ---------------------------------
> We won't tell. Get more on shows you hate to love
> (and love to hate): Yahoo! TV's Guilty Pleasures list. 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org