This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes com.mysql.jdbc.exceptions.jdbc4.communicationsexception communications link failure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "com.mysql.jdbc.exceptions.jdbc4.communicationsexception communications link failure" Watch "com.mysql.jdbc.exceptions.jdbc4.communicationsexception communications link failure" New topic
Author

com.mysql.jdbc.exceptions.jdbc4.communicationsexception communications link failure

Adi Kulkarni
Ranch Hand

Joined: Mar 12, 2009
Posts: 86
Hi,

I'm getting this exception. Actually i'm running a loop and for many iterations its working fine but after around 25 seconds I get this exception for every iteration.

I am using jdk 1.5 , Mysql freeware 5.0 , OS is windows Vista.




Can anyone help me with the issue?

Thanks,
Aditya


SCJP 1.5
Adi Kulkarni
Ranch Hand

Joined: Mar 12, 2009
Posts: 86
Hi all,

Any pointers ?

~Aditya
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Please print the full stack trace with the code which actually throwing the exception, because you said the problem is within a loop and I don't find any loop code?
Between, what is the "connection_timeout' environment variable set to ? also see the max client connection allowed setting in MySQL.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Adi Kulkarni
Ranch Hand

Joined: Mar 12, 2009
Posts: 86
Hi Rohan,

Following is the stack trace. Since DB is being used for comparison for every iteration, the loop comes into picture. So the thing is that the DB query is being executed fine for some iterations after which I get this exception

Cannot connect to database server
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1,252,319,692,146 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2214)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:773)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.GeneratedConstructorAccessor6.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.bt.LibraryDataProvider.compareUsingLibrary(LibraryDataProvider.java:27)
at com.bt.CSVFileProcessor.CompareAndWriteToFile(CSVFileProcessor.java:472)
at com.bt.CSVFileProcessor.processBufferData(CSVFileProcessor.java:428)
at com.bt.CSVFileProcessor.recognitionEngine(CSVFileProcessor.java:83)
at com.bt.MainProcessCall.main(MainProcessCall.java:12)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The driver was unable to create a connection due to an inability to establish the client portion of a socket.

This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable.

For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.

For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).
at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2137)
... 15 more
Caused by: java.net.BindException: Address already in use: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)Entering compare and write
Buffer size 2
Exiting compare and write

at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:290)
... 16 more
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Adi Kulkarni wrote:Hi Rohan,

Kulkarni, "Rohan" is part of my surname

I don't know how you're getting the connection, Its useless to comment anything unless you provide the "actual" code which is responsible for the exception(I think, its a loop code)

FYI,
And the exception itself explain its cause,
Adi Kulkarni wrote:
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The driver was unable to create a connection due to an inability to establish the client portion of a socket.

This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable.

For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.

For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).

Caused by: java.net.BindException: Address already in use: connect
Adi Kulkarni
Ranch Hand

Joined: Mar 12, 2009
Posts: 86
Thanks SAGAR
Adi Kulkarni
Ranch Hand

Joined: Mar 12, 2009
Posts: 86


This is the loop which calls that method
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Now, that's loop code, by any chance, doesn't hint any thing related to db connection.
Between, when I Google the exception, I found plenty hits discussed the same issue, so Google:
The driver was unable to create a connection due to an inability to establish the client portion of a socket.
leglaude leglaudy
Greenhorn

Joined: Mar 06, 2011
Posts: 1
I found a solution that worked for me. (sorry for my english.... I m french)

I was looking for a solution all the day for using JDBC connector with mysql and eclipse. With the last version of JDBC connector 5.1... it does not work so after long hours I decided to change the version of the connector to 5.08 and then I don't have any more problem. It works fine. We are lot experiencing this problem so if it can help à would be pleased.

bye

glaudy
m kanso
Greenhorn

Joined: Oct 12, 2011
Posts: 2
leglaude leglaudy wrote:I found a solution that worked for me. (sorry for my english.... I m french)

I was looking for a solution all the day for using JDBC connector with mysql and eclipse. With the last version of JDBC connector 5.1... it does not work so after long hours I decided to change the version of the connector to 5.08 and then I don't have any more problem. It works fine. We are lot experiencing this problem so if it can help à would be pleased.

bye

glaudy


Hello, I have the same problem, I am looking since 3 days for a solution to activate the connector but no issue ...
I tried the 5.0.8 version and it does not work neither
I am working with

thanks for your help
Marwa
Scott Manno
Greenhorn

Joined: Nov 27, 2011
Posts: 2
If you're running multiple instances of MySQL, make sure the instance you're referencing is up and running.
m kanso
Greenhorn

Joined: Oct 12, 2011
Posts: 2
Scott Manno wrote:If you're running multiple instances of MySQL, make sure the instance you're referencing is up and running.


what is instance ? I am not a database expert so please be more specified and clear,
thanks for the reply
Scott Manno
Greenhorn

Joined: Nov 27, 2011
Posts: 2
m kanso wrote:
Scott Manno wrote:If you're running multiple instances of MySQL, make sure the instance you're referencing is up and running.


what is instance ? I am not a database expert so please be more specified and clear,
thanks for the reply


Two copies. For instance, if you have one (or more) standalone install of MySQL, and/or you're also using something like wampserver, which installs its own copy. Make sure you're looking at the port that corresponds to the install (and that the database is in that copy).
Amit K Srivastava
Greenhorn

Joined: May 31, 2012
Posts: 7
Hi all,
I am having same problem.Application and database both are on Linux Machine .Please help

Code of java connection class is :
//Class Code
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.net.ssl.HttpsURLConnection;

@WebService(serviceName = "NewWebService")
public class NewWebService {

private final String USER_AGENT = "Mozilla/5.0";

@WebMethod(operationName = "isValidUser")
public String isValidUser(@WebParam(name = "phone") String phone, @WebParam(name = "pass") String upass)
{
String mesg = "";
Connection con=null;

try {
con = ConnectionProvider.getCon();
String query = "select * from customer where mobile_phone='" + phone + "' and password='" + upass + "'";
PreparedStatement ps = con.prepareStatement(query);
ResultSet rs = ps.executeQuery();
System.out.println("query----" + query);
boolean status = rs.next();
if (status) {
con = ConnectionProvider.getCon();
String query1 = "select verified from customer where mobile_phone='" + phone + "' ";
PreparedStatement ps1 = con.prepareStatement(query1);
ResultSet rs1 = ps1.executeQuery();
String str = "";
while (rs1.next()) {
str = rs1.getString(1);
}
if (str.equalsIgnoreCase("y")) {
mesg = "you have successfully Login";
} else if (str.equalsIgnoreCase("n")) {
mesg = "please comfirm your account first";
}
} else {
mesg = "UserName or Pasword Wrong";
}

System.out.println("status----" + status);
//java.sql.Driver mySqlDriver = DriverManager.getDriver("jdbc:mysql://202.164.41.156:3306/");
//DriverManager.deregisterDriver(mySqlDriver);

} catch (Exception ex) {
System.out.println("Execption uis : " + ex);
}
return mesg;
}
}

//End class Code

//Error Log from Apache
Execption uis : com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 57,221,771 milliseconds ago. The last packet sent successfully to the server was 57,221,784 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

//
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: com.mysql.jdbc.exceptions.jdbc4.communicationsexception communications link failure
 
Similar Threads
I can't connect to DB
developing jsp page using cewolf
Passing ResultSet to JSP
java with mysql
connecting to mysql, with java, on a mac