Tomcat connecting to MySQL - Ubuntu 8.10 Server

Ambrose Krapacs akrapacs at gmail.com
Mon Nov 17 00:06:01 UTC 2008


I installed 8.10 server and installed the LAMP Server and the Tomcat  
Web Application Server. All necessary components seem to be installed  
and configured fine. I can log into mysql server via the terminal and  
I can run access the tomcat mangager web console as well as run  
servlets and JSPs. The only thing that I can not get to work is  
connecting to MySQL databases via Tomcat web applications.

I'm trying to open the database connection using the following code. I  
have tried using localhost, 127.0.0.1, localhost:3306, 127.0.0.1:3306  
and the results are the same. I've also tried using the overloaded  
version of the getConnection method that takes the username and  
password as separate parameters and still the same results.

Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql:// 
localhost/inventory?user=invuser&password=pass");

I receive the following exception when the second line above is  
executed.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:  
Communications link failure

Last packet sent to the server was 0 ms ago.
	web.db.DatabaseBean.createDatabase(DatabaseBean.java:115)
	web.db.DatabaseBean.install(DatabaseBean.java:89)
	org.apache.jsp.install_jsp._jspService(install_jsp.java:89)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	 
org 
.apache 
.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java: 
342)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	 
sun 
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 
57)
	 
sun 
.reflect 
.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 
43)
	java.lang.reflect.Method.invoke(Method.java:616)
	org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
	java.security.AccessController.doPrivileged(Native Method)
	javax.security.auth.Subject.doAsPrivileged(Subject.java:537)
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java: 
276)
	 
org 
.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java: 
162)

I receive the exact same exception in OS X when I forget to start the  
MySQL Server (i have not configure it to start automatically).  
However, it doesn't seem like that's the problem on my Ubuntu server.  
I have checked the my.cnf and verified that "bind-address=127.0.0.1"  
and that the port it was running on was 3306. From what I can tell  
MySQL is up and running.

Details:
Tomcat 6
Mysql Server version: 5.0.67-0ubuntu6
MySQL J/Connector: mysql-connector-java-5.1.7-bin.jar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20081116/181470dd/attachment.html>


More information about the ubuntu-users mailing list