[LONG]Tomcat jdbc connection pb

From: Gluon (No.Spam_at_cnil.fr)
Date: 08/16/04


Date: Mon, 16 Aug 2004 12:28:07 +0200

Hy,
i'm newbie with Tomcat and i tried to use Hibernate to build some demo
app. As it fails with the jdbc connection, i move for a more basic
example from jakarta:

Can someone help with this?

Here is the various files:

my webapp is called hibernate:
webapps\hibernate\WEB-INF\web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
   PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
   "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
   <display-name>Struts with Hibernate</display-name>

   <!-- Standard Action Servlet Configuration (with debugging) -->
   <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>

   <!-- Standard Action Servlet Mapping -->
   <servlet-mapping>
     <servlet-name>action</servlet-name>
     <url-pattern>*.do</url-pattern>
   </servlet-mapping>

   <!-- The Usual Welcome File List -->
   <welcome-file-list>
     <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>

   <!-- Struts Tag Library Descriptors -->
   <taglib>
     <taglib-uri>/tags/struts-bean</taglib-uri>
     <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
   </taglib>

   <taglib>
     <taglib-uri>/tags/struts-html</taglib-uri>
     <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
   </taglib>

   <taglib>
     <taglib-uri>/tags/struts-logic</taglib-uri>
     <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
   </taglib>

   <taglib>
     <taglib-uri>/tags/struts-nested</taglib-uri>
     <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
   </taglib>

   <taglib>
     <taglib-uri>/tags/struts-tiles</taglib-uri>
     <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
   </taglib>

        <!-- -->
        <resource-ref>
       <description>DB Connection</description>
       <res-ref-name>jdbc/hibernate</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
   </resource-ref>

</web-app>

Here is the Tomcat 5.0\conf\Catalina\localhost\Hibernate.xml
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="Struts with Hibernate" docBase="hibernate"
path="/Hibernate" reloadable="true" workDir="D:\Program Files\Apache
Software Foundation\Tomcat 5.0\webapps\hibernate\work">
   <Logger className="org.apache.catalina.logger.FileLogger"
prefix="hibernateWebApp." timestamp="true" verbosity="0"/>
   <Manager className="org.apache.catalina.session.StandardManager"
maxActiveSessions="4" maxInactiveInterval="1800">
   </Manager>
   <Resource name="jdbc/hibernate" type="javax.sql.DataSource"/>
   <ResourceParams name="jdbc/hibernate">
     <parameter>
       <name>factory</name>
       <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
     </parameter>
     <parameter>
       <name>validationQuery</name>
       <value>select id from item;</value>
     </parameter>
     <parameter>
       <name>url</name>
       <value>jdbc:mysql://localhost:3306/test?autoReconnect=true</value>
     </parameter>
     <parameter>
       <name>password</name>
       <value>testuser</value>
     </parameter>
     <parameter>
       <name>maxActive</name>
       <value>10</value>
     </parameter>
     <parameter>
       <name>maxWait</name>
       <value>1000</value>
     </parameter>
     <parameter>
       <name>driverClassName</name>
       <value>com.mysql.jdbc.Driver</value>
     </parameter>
     <parameter>
       <name>username</name>
       <value>testuser</value>
     </parameter>
     <parameter>
       <name>maxIdle</name>
       <value>30</value>
     </parameter>
   </ResourceParams>
</Context>

and now the jsp webapps\hibernate\pages\Test.jsp:
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<sql:query var="rs" dataSource="jdbc/hibernate">
select * from item
</sql:query>

<html>
   <head>
     <title>DB Test</title>
   </head>
   <body>

   <h2>Results</h2>

<c:forEach var="row" items="${rs.rows}">
     ID ${row.id}<br/>
     NAME ${row.name}<br/>
     DESCRIPTION ${row.description}<br/>
</c:forEach>

   </body>
</html>

the mySQL connection works fine:
C:\mysql\bin>mysql test -utestuser -ptestuser
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.0.20a-nt-max

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| item |
+----------------+
1 row in set (0.05 sec)

mysql> show columns in item;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| id | bigint(11) | | PRI | NULL | auto_increment |
| name | varchar(32) | | | | |
| description | longtext | YES | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
3 rows in set (0.05 sec)

but the servelt raise the following exception:

javax.servlet.ServletException: Unable to get connection, DataSource
invalid: "org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC
driver of class '' for connect URL 'null'"
        org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
        org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
        org.apache.jsp.pages.Test_jsp._jspService(Test_jsp.java:81)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

cause mère

javax.servlet.jsp.JspException: Unable to get connection, DataSource
invalid: "org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC
driver of class '' for connect URL 'null'"
        org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:276)
        org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:159)
        org.apache.jsp.pages.Test_jsp._jspx_meth_sql_query_0(Test_jsp.java:100)
        org.apache.jsp.pages.Test_jsp._jspService(Test_jsp.java:58)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:810)



Relevant Pages

  • Re: VFP8 & MySQL
    ... > VFP functions like NVL to a MySQL one, definitely it made the switch very ... > About your connection problem, I have mine setup as default for 100 ... As for the server, we left it ... The server crashed and corrupted the database. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Does apache stop a script mid execution ?
    ... If the user calls a time consuming script and then stops or refreshes ... How does it relate to e.g. a script performing a large mysql query? ... 2.b) how the connection is set up. ... the server stops the script execution. ...
    (comp.lang.php)
  • MySQL on Win 98
    ... I'm just getting into MySQL and I'm trying to learn about it at home. ... and created a DSN connection for it. ... User: root ... ODBC Data Source Administrator and get a "success" result. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: VFP8 & MySQL
    ... Main Location and 3 branches (these are remotely accessing MySQL at the main ... About your connection problem, I have mine setup as default for 100 ... As for the server, we left it alone. ... The server crashed and corrupted the database. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Java and MySql program example ?
    ... > I am trying to learn Java and need an example program with MySql ... > MySql database. ... Database connection established ...
    (comp.lang.java.programmer)