I have a java program, when i log in, after ~600,000 milliseconds (i actually tried several times, and its always ~600,000, thats why i think theres somewhere set up a timeout for 600,000 miliseconds) my database connection crashes and my program no longer works (it always needs to be connected to database). It gives me Communication link failure error. I Here are my mysql connection settings:
import java.sql.*;
import javax.swing.*;
public class mysqlconnect {
Connection conn = null;
public static Connection ConnectDb() {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://server_name/database_name","user_name","user_password");
return conn;
}catch (Exception e) {
JOptionPane.showMessageDialog(null, "Cant connect to db");
return null;
}
}
}
I tried adding ?autoReconnect=true & tcpKeepAlive to my code, but no luck. Is there any way to go to phpmyadmin and change some setting there (increase the timeout time)?
解决方案SET SESSION wait_timeout = 999999;//or anything you want
From mysql command line that will increase the timeout value. To be able to see the value:
SHOW VARIABLES LIKE 'wait_timeout';