I am getting this error when i log into my program and leave it for a minute or so:
com.mysql.jdbc.exceptions.jdbc4.CommuncationsException: Communications link failure
The last packet succesfully received from the server was 590,905 miliseconds ago. The last packet sent succesfully to the server was (cant remember correct number) miliseconds ago.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
The connection to the database ends here and my program no longer works. Here is my connection to mysql db config file:
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://MYSERVER.COM/MY_DATABASE","USERNAME","PASSWORD");
//JOptionPane.showMessageDialog(null, "Connection successfull");
return conn;
}catch (Exception e) {
JOptionPane.showMessageDialog(null, "Cant connect to db");
return null;
}
}
}
After doing some research i think i need to add more configurations to this file, but not sure what to add or even if i really need to modify this file. Any suggestions?
Original code with only wrong username password:
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://rude.su.lt/data_base1","USERNAME","PASSWORD");
Connection conn = DriverManager.getConnection("jdbc:mysql://rude.su.lt/data_base1","USERNAME","PASSWORD");
//JOptionPane.showMessageDialog(null, "Prisijungimas pavyko");
return conn;
}catch (Exception e) {
JOptionPane.showMessageDialog(null, "Prisijungimas prie duomenų bazės nepavyko");
return null;
}
}
}