3

I am currently working in a java program involving mysql. I encountered a problem with these message:

Communications link failure. The last packet successfully received from the server was 174,165,153 milliseconds ago. The last packet sent successfully to the server was 4 milliseconds ago.

I believe this has to do with the session variable 'wait_timeout'. My assumption could be wrong though so I am confirming it here. Is this really because of the 'wait_timeout' session variable? Does this error mean that my database connection is "expired" in a sense that the session timeout already lapsed? If yes, I have another problem.. I cannot reproduce the said error..

This is what I am trying in order to replicate the error.

  1. Setting the wait_timeout variable to 5 which is originally 28800( 8 hrs ).

    mysql> set session wait_timeout=5;

  2. Thinking that my next attempt to access database would apply this, I would run this code:

        Class.forName("com.mysql.jdbc.Driver");
        oConnection = DriverManager.getConnection(sUrl,sUser,sPass);
        System.out.println("Database Connection Established.\n");
        Thread.sleep(6000);
    
        executeSimpleQuery();
    

    The executeSimpleQuery() function just executes a simple SELECT * FROM statement to check if the connection is still working. Apparently, if the wait_timeout is just 5 and I've made the thread sleep for 6 seconds, the connection would now be expired and the error should be produced. But, the expected result does not happen instead it performs the query.

What should i do to replicate the error?

1 Answer 1

3

You set wait_timeout=5 for current session; then opened another session (in java application) and executed the query. Try to set this variable after the opening connection, or set it globally.

For example -

SET @@global.wait_timeout = 15; -- Set global variable
SET @@local.wait_timeout = 25; -- Set session variable
SELECT @@global.wait_timeout, @@local.wait_timeout; -- Check global and session variables
Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much for this. although i did not use the global setting of the wait_timeout because i need to handle connection per session. thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.