Laurent Hinoul

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” - John F. Woods

How to fix java.io.EOFException: Can not read response from server for MySQL

Hi, I made a java program where much database queries are processed in MySQL. After some time running, I got an error message:

After some research, it seams that the MySQL driver is not reconnecting after it lost its connection to the database.

First, append the following line ?autoReconnect=true to your jdbc connection string:

Next, you must find out what the wait timeout is of your MySQL. Run the query ‘show variables’ an search for wait_timeout. for me, it has the value 60.

Now we know the timeout, we can adjust our datasource. I use Hibernate and C3P0. First, make sure you have the following dependencies to make hibernate and C3P0 work correctly:

Now we edit the datasource values. Just make sure that the size of ‘idleConnectionTestperiod’ is smaller than your wait_timeout:

It’s done! Nice work! I hope it did the trick for you too. Enjoy!

Leave a Reply

%d bloggers like this: