• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat 5.5.9 getting Database Connection

 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic