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" <[EMAIL PROTECTED]>
To: <users@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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]