commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Cook <bc...@printtime.com>
Subject Re: [DBCP] Unable to create and use a Connection Pool
Date Tue, 19 Jul 2005 20:56:19 GMT

When you are declaring the JNDI Resources in server.xml I believe it has 
to be inside a <Context> tag.  I had a lot more luck declaring all of it 
in the context.xml file in conf/Catalina/localhost/myapp.xml.  This is 
also helpful when needing to make a change you do not have to reset 
Tomcat and take down all of your apps.


Examples :

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">

   <session-config>
     <session-timeout>
             30
     </session-timeout>
   </session-config>

   <welcome-file-list>
     <welcome-file>
             index.jsp
         </welcome-file>
   </welcome-file-list>

   <resource-ref>
   <description>
     Some details about your DB
   </description>
   <res-ref-name>
     jdbc/WhatEverNameHere
   </res-ref-name>
   <res-type>
     javax.sql.DataSource
   </res-type>
   <res-auth>
     Container
   </res-auth>
</resource-ref>

</web-app>
---------------------------------------------------


context.xml
conf/Catalina/localhost/myapp.xml.
---------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/ordering" reloadable="true">

   <Resource auth="Container"
         driverClassName="com.mysql.jdbc.Driver"
         maxActive="6"
         maxIdle="2"
         name="jdbc/WhatEverNameHere"
         password="password"
         type="javax.sql.DataSource"
         url="jdbc:mysql://xxx.xxx.xxx.xxx/DBName"
         username="MySQLUserName"/>

   </Context>


---------------------------------------------------



Ramon Garcia wrote:
> Hi,
> I have a problem tring to create and use a connection pool, I'm using 
> Tomcat
> 5.0.28 and MySQL.
> I followed the examples of the  "JNDI Datasource HOW-TO" But when I use it
> the server shows a "javax.naming.NameNotFoundException"
> My conifuration files are like:
> 
> CATALINA_HOME/conf/server.xml
> --------------------------------
> <?xml version='1.0' encoding='utf-8'?>
> <Server>
>  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
>  <Listener
> className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
>  <GlobalNamingResources>
>    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
>    <Resource auth="Container" description="User database that can be
> updated and saved" name="UserDatabase"
> type="org.apache.catalina.UserDatabase"/>
>    <Resource name="jdbc/ramon" type="javax.sql.DataSource"/>
>    <ResourceParams name="UserDatabase">
>      <parameter>
>        <name>factory</name>
>        <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
>      </parameter>
>      <parameter>
>        <name>pathname</name>
>        <value>conf/tomcat-users.xml</value>
>      </parameter>
>    </ResourceParams>
>    <ResourceParams name="jdbc/ramon">
>      <parameter>
>        <name>validationQuery</name>
>        <value>select * from pista;</value>
>      </parameter>
>      <parameter>
>        <name>maxWait</name>
>        <value>5000</value>
>      </parameter>
>      <parameter>
>        <name>maxActive</name>
>        <value>4</value>
>      </parameter>
>      <parameter>
>        <name>password</name>
>        <value>client</value>
>      </parameter>
>      <parameter>
>        <name>url</name>
>        <value>jdbc:mysql://localhost:3306/proves</value>
>      </parameter>
>      <parameter>
>        <name>driverClassName</name>
>        <value>org.gjt.mm.mysql.Driver</value>
>      </parameter>
>      <parameter>
>        <name>maxIdle</name>
>        <value>2</value>
>      </parameter>
>      <parameter>
>        <name>username</name>
>        <value>client</value>
>      </parameter>
>    </ResourceParams>
>  </GlobalNamingResources>
>  <Service name="Catalina">
>    <Connector acceptCount="100" connectionTimeout="20000"
> disableUploadTimeout="true" port="8080" redirectPort="8443"
> maxSpareThreads="75" maxThreads="150" minSpareThreads="25">
>    </Connector>
>    <Connector port="8009" protocol="AJP/1.3"
> protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"
> redirectPort="8443">
>    </Connector>
>    <Engine defaultHost="localhost" name="Catalina">
>      <Host appBase="webapps" name="localhost">
>        <Logger className="org.apache.catalina.logger.FileLogger"
> prefix="localhost_log." suffix=".txt" timestamp="true"/>
>      </Host>
>      <Logger className="org.apache.catalina.logger.FileLogger"
> prefix="catalina_log." suffix=".txt" timestamp="true"/>
>      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
>    </Engine>
>  </Service>
> </Server>
> --------------------------------
> 
> conf/Catalina/localhost/myapp.xml
> --------------------------------
> <?xml version='1.0' encoding='utf-8'?>
> <Context docBase="prova" path="/prova"
> workDir="work\Catalina\localhost\prova">
> <ResourceLink name="jdbc/ramon" type="javax.sql.DataSource"
> global="jdbc/ramon"/>
>  <Logger className="org.apache.catalina.logger.FileLogger" prefix="prova."
> timestamp="true"/>
> 
> </Context>
> --------------------------------
> 
> and finally the web.xml file:
> ...
>  <resource-ref>
>    <description>Prova BD</description>
>    <res-ref-name>jdbc/ramon</res-ref-name>
>    <res-type>javax.sql.DataSource</res-type>
>    <res-auth>Container</res-auth>
>  </resource-ref>
> ..
> 
> What is my problem? I forgot to do something?
> 
> Thanks and Best Regards.
> 
> Ramon Garcia
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


-- 
Brian Cook
Digital Services Analyst
Print Time Inc.
bcook@printtime.com
913.345.8900


Mime
View raw message