tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Smith <d...@cornell.edu>
Subject Re: 6.0.13 MySQL DBCP Example
Date Thu, 09 Aug 2007 09:49:53 GMT
Ok... tomcat 6.0.13

1. I would merge the <Context .... /> element from server.xml to your 
context.xml file and remove the Context element from your server.xml.  
Placing this element in server.xml is not recommended anymore as it 
means a restart of tomcat to deploy/undeploy webapps.  Also having the 
Context definition in two places for one webapp will undoubtedly cause 
problems with one overriding the other.

2. Trim any spaces in the element attributes.  I saw an extraneous space 
in the driverClassName attribute below.

3. It's not recommended you add autoReconnect=true to the mysql db url.  
It has it's uses, but not in a database pool.  Instead, use a 
validationQuery attribute in your Resource element to test and validate 
connections before your app borrows them.

4. I'm assuming the mysql-connector-java-*.jar file is stored in the 
$CATALINA_HOME/lib folder and not present in your webapp's WEB-INF/lib 
folder.

Let us know what happens.  If it still doesn't work, let us see the new 
context.xml file and be sure there isn't a <Context ...> element in the 
server.xml.

--David

G M wrote:
> I've been trying for days now to establish a jdbc resource for mysql in
> tomcat 6.0.13
>
> To whom it may correspond:
>
> I get the following error
>
> Unable to get connection, DataSource invalid:
> "org.apache.tomcat.dbcp.dbcp.SQLNestedException
> : Cannot create JDBC driver of class '' for connect URL 'null'"
>
>
> I have the driver mysql-connector-java-5.0.6-bin.jar copied to
> $CATALINA_HOME/lib
>
> My application web.xml looks like this: (exactly as the example)
>
> <web-app 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 "
>     version="2.4">
>   <description>MySQL Test App</description>
>   <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>
>
> In
> http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.htmlthere
> is this instruction:
>
> Add this in between the </Context> tag of the examples context and the
>   
>> </Host> tag closing the localhost definition. If there is no such tag, you
>> can add one as illustrated in the Context<http://tomcat.apache.org/tomcat-6.0-doc/config/context.html>and
>> Host <http://tomcat.apache.org/tomcat-6.0-doc/config/host.html>configuration
references, and  repeated below for your convenience.
>>     
>
>
> In my own opinion this is quite ambiguous. After several search in the mail
> repositories. I have this as my server.xml configuration (i deleted the
> comments for easy reading)
>
> <Server port="8005" shutdown="SHUTDOWN">
>   <Listener className="org.apache.catalina.core.AprLifecycleListener"
> SSLEngine="on" />
>   <Listener className="org.apache.catalina.core.JasperListener" />
>   <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
> />
>   <Listener className="
> org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
>
>   <GlobalNamingResources>
>     <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" protocol="HTTP/1.1"
>                connectionTimeout="20000"
>                redirectPort="8443" />
>     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
>      <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="/DBTest" docBase="DBTest"
>             debug="5" reloadable="true" crossContext="true">
>
>
>             <Resource name="jdbc/TestDB" auth="Container" type="
> javax.sql.DataSource"
>                maxActive="100" maxIdle="30" maxWait="10000"
>                username="gabo" password="huevos" driverClassName="
> com.mysql.jdbc.Driver "
>
> url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>
>
>         </Context>
>       </Host>
>     </Engine>
>   </Service>
> </Server>
>
> In my own opinion the problem is with server.xml, should I add something to
> context.xml?
> Any comment, hint or tip would be greatly appreciated.
>
> Regards
>
> Gabriel
>
>   


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


Mime
View raw message