Mark Witczak wrote:
> I'm very new to Tomcat, connection pooling, JSP, etc. and I've been
> banging my head against a wall for two weeks trying to get a simple
> program to connect to a MySQL database.
>
> *Vital Stats:*
> Ubuntu 9.10, Java 1.6.0_0,  Java Servelet 2.5, Java Server Pages 2.1,
> JSTL 1.2, Apache2, Tomcat 6.0.20, MySQL 5.1.41 & 5.0.67
> MySQL Connector/J 5.1.11 (also 5.1.10) - in $CATALINA_HOME/lib
> dbcp 1.2.1 - in $CATALINA_HOME/lib
> (all standard Ubuntu issue)
>
> *testapp/WEB-INF/web.xml:*
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <web-app xmlns="http://java.sun.com/xml/ns/javaee";
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
>    version="2.5">
>
> <description>
>       Servlet and JSP Examples.
> </description>
> <display-name>Servlet and JSP Examples</display-name>
>
> <resource-ref>
> <description>DB Connection</description>
> <res-ref-name>jdbc/mydatabase</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
> </web-app>
>
> *testapp/META-INF/context.xml:*
> <?xml version="1.0" encoding="UTF-8"?>
>
> <Context path="/junk" docBase="junk"
>         debug="5" reloadable="true" crossContext="true">
>
> <Resource name="jdbc/mydatabase" auth="Container"
> type="javax.sql.DataSource"
>                maxActive="100" maxIdle="30" maxWait="10000"
>                username="foo" password="bar"
> driverClassName="com.mysql.jdbc.Driver"
>                url="jdbc:mysql://test.hostname.com:3306/database_test1"/>
> </Context>
>
> *testapp/testapp.jsp:*
> <%@ page contentType="text/html" %>
> <%-- These libraries are required for the <c> and <sql> tags --%>
> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"; %>
> <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"; %>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> <html>
> <head>
> <title>JNDI DBCP Test Page</title>
> </head>
> <body>
>
> <h1>JNDI DBCP Test Page</h1>
> <br/>Executing the query ...
> <br/>
>
> <%-- Note: Enter a query that is valid for your database here --%>
> <sql:query var="result" dataSource="jdbc/mydatabase">
>         SELECT company FROM manuals
> </sql:query>
> </body>
> </html>
>
> I create the WAR (jar cvf testapp.war *), undeploy the old version and
> redeploy the new one through Tomcat Web Application Manager. Then
> restart Tomcat (sudo /etc/init.d/tomcat restart). The result is:
>
> Jan 21, 2010 9:40:35 PM org.apache.catalina.core.ApplicationContext log
> INFO: ContextListener: contextInitialized()
> Jan 21, 2010 9:40:35 PM org.apache.catalina.core.ApplicationContext log
> INFO: SessionListener: contextInitialized()
> Jan 21, 2010 9:43:06 PM org.apache.catalina.core.StandardWrapperValve
> invoke
> SEVERE: Servlet.service() for servlet jsp threw exception
> javax.servlet.jsp.JspException: Unable to get connection, DataSource
> invalid: "org.apache.commons.dbcp.SQLNestedException: Cannot create
> PoolableConnectionFactory (Communications link failure
>
> The last packet sent successfully to the server was 0 milliseconds
> ago. The driver has not received any packets from the server.)"
>         at
> org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(Unknown
> Source)
>         at
> org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(Unknown
> Source)
>         at
> org.apache.jsp.test_jsp._jspx_meth_sql_005fquery_005f0(test_jsp.java:188)
>         at org.apache.jsp.test_jsp._jspService(test_jsp.java:138)
>         at
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> Blah, Blah, Blah....
>
> *More info: *The connection to MySQL tested successfully using the
> command line 'mysql'. There are no firewalls, that I can find, between
> the servers.
>
> What is going on here? What am I missing? What is going on here? How
> do I fix it?
>
> -Do I need to create a "foo" user in the tomcat-users.xml?
> -Do I have to mess with the policy files? or security?
>
> Thanks for your help.
> Mark
>
>
>
What options did you use with the mysql command to test MySQL?  Be
careful as the command line will use unix sockets instead of tcp/ip by
default.  The JDBC driver won't be able to do that.

--David


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to