Connector/J "Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost."
I've been trying for a day and a half to get this working with no luck. I'm running Java 6/mysql 5/ mandriva 2008 / eclipse/ connectorJ 5.0.8, and have tried using hibernate and connecting manually with no luck. I've tried reinstalling mysql and different versions of java and connector j, and it changes the output slightly, but with the same CommunicationsException followed by Connection failure.
I've looked all over for answers, but I have found almost nothing. This happens all the time, not after leaving the connection for a while as has been suggested otherwise.
All help desperately welcomed.
(PS apologies if this is triple posted, been having trouble with this forum today)
Cannot connect to database server
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
com.mysql.jdbc.CommunicationsException
MESSAGE: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
MESSAGE: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
STACKTRACE:
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:1997)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2411)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2916)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1300)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.samatkinson.Connect.main(Connect.java:16)
** END NESTED EXCEPTION **
Last packet sent to the server was 288 ms ago.
STACKTRACE:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
MESSAGE: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
STACKTRACE:
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:1997)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2411)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2916)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1300)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.samatkinson.Connect.main(Connect.java:16)
** END NESTED EXCEPTION **
Last packet sent to the server was 288 ms ago.
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2622)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2916)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1300)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.samatkinson.Connect.main(Connect.java:16)
** END NESTED EXCEPTION **
Last packet sent to the server was 291 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.samatkinson.Connect.main(Connect.java:16)
------------------------------
Example Connector Class:
package com.samatkinson;
import java.sql.*;
public class Connect
{
public static void main (String[] args)
{
Connection conn = null;
try
{
String userName = "root";
String password = "password";
String url = "jdbc:mysql://127.0.0.1:2273/PADPAL";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server");
e.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
(also note, i've tried with ip and localhost)
Subject
Written By
Posted
Connector/J "Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost."
October 30, 2007 07:36AM
February 08, 2008 04:35AM
February 09, 2008 04:26PM
February 10, 2008 11:33AM
February 10, 2008 02:07PM
February 11, 2008 07:33AM
February 11, 2008 08:22AM
February 11, 2008 10:19AM
February 11, 2008 02:54PM
February 13, 2008 03:47AM
February 13, 2008 06:17AM
February 14, 2008 12:37PM
December 18, 2008 05:23AM
February 11, 2008 01:45PM
February 11, 2008 11:41PM
February 19, 2008 10:49AM
February 19, 2008 10:51AM
February 19, 2008 11:23AM
February 19, 2008 11:25AM
February 19, 2008 12:03PM
February 20, 2008 06:05PM
September 24, 2008 02:55AM
November 27, 2008 01:56AM
November 30, 2008 03:15AM
February 03, 2009 03:00PM