I have a Java program. When I log in, after ~600,000 milliseconds (I actually tried several times, and it is always ~600,000. That is why I think there is 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)?
mysql> SELECT CONNECTION_ID(); The following is the output that shows the current connection id. The following is the syntax to check all the current information with a single command.
Can I adjust the timeout? Yes, go to Preferences, SQL Editor, and adjust the DBMS connection read time out option that defaults to 600 seconds. This sets the maximum amount of time (in seconds) that a query can take before MySQL Workbench disconnects from the MySQL server.
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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With