Connection Pool: MySQL Communications link failure
The Problem And The Solution
While using a MySQL connection pool in Java, I received a MySQL Communications link failure Exception (see below).
In order to solve communication link failure exception:
- I have removed JDBC property autoReconnect=true and put only the JDBC property autoReconnectForPools=true
- I have added the connection properties:
- testOnBorrow
- testWhileIdle
- timeBetweenEvictionRunsMillis
- minEvictableIdleTimeMillis
See for example: How to set up a MySQL connection pool in Java
The MySQL CommunicationsException: Communications link failure Exception
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error : ** BEGIN NESTED EXCEPTION ** com.mysql.jdbc.exceptions.jdbc4.CommunicationsException MESSAGE: Communications link failure Last packet sent to the server was 0 ms ago. STACKTRACE: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2871) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3414) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1485) ... at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2431) at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2882) ... 14 more ** END NESTED EXCEPTION ** |

One Comment
Leave a Reply
Hi,
I have the same error, but in my program I try to connect to server host in other computer, I need some help to connect my Data Base in MySQL.
This is my code:
Driver = “com.mysql.jdbc.Driver”;
try {
Class.forName(Driver).newInstance();
System.out.println(“Driver Conectado”);
} catch (Exception ex) {
System.out.println(“Error “+ex.getMessage());
}
try {
String url = “jdbc:mysql://192.168.0.1:3306/BD”;
DriverManager.getConnection(url, “root”, “root”);
conexion.setAutoCommit(true);
} catch (Exception ex) {
System.out.println(“Error\n”);
System.out.println(“Error “+ex.getMessage());
}
Computers are in LAN network.
Please help me.