File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes java.sql.SQLException: Communication link failure: null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: Communication link failure: null" Watch "java.sql.SQLException: Communication link failure: null" New topic
Author

java.sql.SQLException: Communication link failure: null

Vikas
Ranch Hand

Joined: Dec 16, 2004
Posts: 63
Hi all,

I am trying to connect to the MySQL database but am getting the following unusual exception can anybody help me in this regards??

java.sql.SQLException: Communication link failure: null
at org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:261)
at org.gjt.mm.mysql.Connection.(Connection.java:229)
at org.gjt.mm.mysql.Driver.connect(Driver.java:126)
at java.sql.DriverManager.getConnection(DriverManager.java:515)
at java.sql.DriverManager.getConnection(DriverManager.java:174)
at org.apache.jsp.test$jsp._jspService(test$jsp.java:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Thread.java:579)
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

Vikas,
It looks like mySql might be down or there is an error connecting. First check you can access mySql from the command line. Also, if it the database is on a different machine, check the ports are open.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I usually give the same advice for problems like this: it's easier to download SquirrelSQL and debug your JDBC connection here and then move the settings to your application. This way you don't have to keep compiling.
Vikas
Ranch Hand

Joined: Dec 16, 2004
Posts: 63
>> Vikas,
>> It looks like mySql might be down or there is an error connecting. First >> check you can access mySql from the command line. Also, if it the
>> database is on a different machine, check the ports are open.

Thank you Jeanne and David,

I checked the MySQL accessibilty from the command line which is on the same machine and I can login through the command line I cheked the porta as well with telnet mysql 3306 which displayed a window with some strange message which diappears after a while I think everything is fine with that. Do I need to re-install the MySQL??

Thank you
Vikas
Vikas
Ranch Hand

Joined: Dec 16, 2004
Posts: 63
Hi,

I tried the same code on different machine with different MySQL server but the result is same "java.sql.SQLException: Communication link failure: null
"

what could be wrong with the following piece of code??


package test.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

public class saveDB
{
private Connection conn;
String url="jdbc:mysql://192.168.1.157:3306/test";
String user="root";
String password="";
public saveDB() {
// open Database connection
try {
Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection(url,user,password);
System.out.println("*** Database connected");
} catch (ClassNotFoundException e) {
System.err.println("Can't instantiate Database Driver");
} catch (SQLException e) {
System.err.println("Can't connect to Database" +e);
}
}

Thank you
Vikas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.SQLException: Communication link failure: null