Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error connecting through JDBC after a period of time

843859Jun 5 2010 — edited Nov 20 2014
Hello,

I am having a problem in a J2SE program that uses mysql-connector-j to contact a MySQL database.

It connects fine, and my first couple queries work no problem. If I have not made a query after a period of time (60 seconds or so), all subsequent queries give me this error:
06/05 12:06:24| Main.DatabaseManager@5af6ac0b Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 39,558 milliseconds ago.  The last packet sent successfully to the server was 12 milliseconds ago.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 39,558 milliseconds ago.  The last packet sent successfully to the server was 12 milliseconds ago.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
...

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:2503)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2953)
        ... 10 more
I recently migrated all my code to a new server. The code was fine for over 6 months on my previous server, so I'm assuming this is some MySQL timeout setting or something. Accessing MySQL through PHP works fine, and I have no connectivity issues. Accessing through Java works fine for the first few queries, but after a short time all queries fail as above.

Does anyone have any suggestions? Experience with this before?

Thank you,

Jesse
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 6 2010
Added on Jun 5 2010
9 comments
651 views