This question has been asked a couple of times in SO and many times in other sites. But I didn\'t get any satisfiable answer.
My problem:
I have a java web app
It might be Firewall related problem.
This is EndOfFileException in java, happens when your cursor start point is on the end point or when database connection closed because of some unexpected exception.
Got this error in PHPStorm while trying to connect and/or get some data from mysql server. Checkbox "single connection mode" fixed things for me. I'll just leave it here. Perhaps this will help some martyr in the future.
https://www.jetbrains.com/help/phpstorm/configuring-database-connections.html
I had this problem but I it wasn't possible for me to make changes in MySQL database configuration. Therefore I ensured that in my sql connector class the connection is always closed before it's initiated again. Something like:
public static Connection getConnection() {
if (DatabaseConnnector.conn == null) {
initConn();
} else {
try {
DatabaseConnnector.conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
initConn();
}
return DatabaseConnnector.conn;
}
And this solved the problem.
i meet the same problem, it caused by lock for too much time.
we have a long transcation A, if execute it, the other trascation will be locked util transcation A finished, so the others always be killed by our mysql tool(pt-kill)
The connection has failed, possibly due to a firewall idle-timeout, etc. If you don't have your JDBC driver configured to reconnect on failure, then this error will not go away unless you open a new connection.
If you are using a database connection pool (you are using one, right?), then you probably want to enable it's connection-checking features like issuing a query to check to see if the connection is working before handing it back to the application. In Apache commons-dbcp, this is called the validationQuery
and is often set to something simple like SELECT 1
.
Since you are using MySQL, you ought to use a Connector/J-specific "ping" query that is lighter-weight than actually issuing a true SQL query and set your validation query to /* ping */ SELECT 1
(the ping part needs to be exact).