当我登录我的程序并将其放置一分钟左右时出现此错误:
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.
到数据库的连接到此结束,我的程序不再工作。这是我与 mysql db 配置文件的连接:
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;
}
}
}
在做了一些研究之后,我认为我需要向这个文件添加更多配置,但不确定要添加什么,或者即使我真的需要修改这个文件。有什么建议么?
只有错误用户名密码的原始代码:
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;
}
}
}