1

Basically, I created a Connection con variable and initialised it correctly. The connection and the query and all operation from my Java code to the MySQL Database works perfect. The problem is that if after exactly one minute if the user didn't interact with program, and then I preformed any operation with database (Using the Java program) it shows the following error.

Communications link failure

The last packet successfully received from the server was 139,417 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.

and after I press ok on the message dialog this comes up:

No operation allowed after connection closed.

I already checked the connection timeout using

System.out.println(con.getNetworkTimeout());

it showed me "0", which from a basic online reading it should be unlimited, I guess.

I want to extend it from disconnecting after 1 minute to 3 or 4 minutes.

halfer
  • 19,824
  • 17
  • 99
  • 186
IL876ANI
  • 11
  • 2
  • In my experience, you need to change the MySQL server-side configuration. – Stephen C Apr 04 '16 at 15:46
  • I think it might have to do something with the timeouts. con.query('SET GLOBAL connect_timeout=28800') con.query('SET GLOBAL wait_timeout=28800') con.query('SET GLOBAL interactive_timeout=28800'). Got the above information from the following post http://stackoverflow.com/questions/14726789/how-can-i-change-the-default-mysql-connection-timeout-when-connecting-through-py – LearningPhase Apr 04 '16 at 16:00
  • @LearningPhase i checked it before, But there is no such thing as con.query();, i tried creating a statement but it displayed an error saying i need super privileges to use these commands. – IL876ANI Apr 05 '16 at 07:31
  • Can you please look at the following link in stackoverflow. It gives a lot of solutions . http://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc-and-mysql – LearningPhase Apr 05 '16 at 10:52

0 Answers0