This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Tomcat 5.5.9 getting Database Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat 5.5.9 getting Database Connection" Watch "Tomcat 5.5.9 getting Database Connection" New topic
Author

Tomcat 5.5.9 getting Database Connection

Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
I am having trouble getting a database connection using Tomcat 5.5.9 on WIndows XP. Here is what I have:

* I have put mysql-connector-java-3.1.10-bin.jar in TOMCAT_HOME/common/lib/directory
* I create a context.xml file that I put in the meta-inf directory of my war file. Here is the contents:

<Context path="/quickstart" docBase="quickstart" debug="1" reloadable="true">
<Resource name="jdbc/quickstart" auth="Container" type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="quickstart" password="quickstart"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/quickstart"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"/>
</Context>

* in my web.xml I have:

<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>Hibernate Test</description>
<servlet>
<servlet-name>Quickstart</servlet-name>
<servlet-class>org.hibernate.examples.quickstart.QuickstartServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Quickstart</servlet-name>
<url-pattern>/quick</url-pattern>
</servlet-mapping>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/quickstart</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>

* in my servlet I just have some code that does:



When I run this servlet, I get the following message print out from the catch clause above:

Cannot create JDBC driver of class '' for connect URL 'null'

It can't seem to find the class. Should I put the context.xml somewhere else or has anyone had success putting it in the meta-inf directory? Any help would be apprectiated!
Thanks
Brian
[ July 07, 2005: Message edited by: Brian Nice ]
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Something you can try -

Rename your context.xml file to quickstart.xml (not exactly required though, i think) , and place it under TOMCAT_HOME/conf/Catalina/localhost.

There is more information on deploying applications in Tomcat at
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/appdev/deployment.html

HTH.


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
Great, that worked. Any idea on why it doesn't work under the meta-inf directory? that is what the documentation seems to want you to do
Thanks
Brian
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

I didnt read the documentation throughly, but from what I remember, the context information is picked from META-INF directory only when you use one of the Tomcat tools (Deployer?Manager?) to deploy the application.

This may not be done under other conditions, for example if you are deploying an expanded directory or manually copying a war to webapps.

Cheers.
 
jQuery in Action, 2nd edition
 
subject: Tomcat 5.5.9 getting Database Connection
 
Similar Threads
Cannot load JDBC driver for mysql in Servlet
Eclipse+Tomcat+JNDI
TOMCAT 5.5.4 + Datasource in ROOT not working
Configure tomcat resource factory
Database connectivity issue