Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6737271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:13:46+00:00 2026-05-26T11:13:46+00:00

I am currently working in a java program involving mysql. I encountered a problem

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:13:47+00:00Added an answer on May 26, 2026 at 11:13 am

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we are currently working on a new web application using Java and MySql. We
I am currently working on a simple line program in java. There will be
I'm back with another similar question. I am currently working on a Java program
Im currently working on a java program and I need to read/write to the
I'm currently working with Java to write a program that does an EAI between
How can I change the current working directory from within a Java program? Everything
I'm currently working on a Java project that is emitting the following warning when
I am currently working on 100+ Java Objects created by someone with no JPA/Hibernate
I'm currently working on building a java web app. I've been looking to use
I am coming from Java and am currently working on a C# project. What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.