成功从服务器接收到的最后一个数据包是67,265,496毫秒之前。成功发送到服务器的最后一个数据包是67,265,496毫秒之前。大于服务器配置的“ wait_timeout”值。在应用程序中使用该连接之前,您应该考虑过期和/或测试连接有效性,或者增加服务器为客户端超时配置的值,或者使用Connector / J连接属性'autoReconnect = true'来避免此问题。”
我的Java代码
private static Connection mConnection = null;
//method to be called to get connection
public static Connection getConnection() {
init(); //if connection closes reopen
return mConnection;
}
这是初始化连接时函数中的代码
driver = "com.mysql.jdbc.Driver";//p.getProperty("jdbc.driver");
host = "localhost";//"127.0.0.1";//p.getProperty("connection.host");
username = "abc";//p.getProperty("db.user");
password = "abcd#";//p.getProperty("db.password");
port = "3307";//p.getProperty("connection.port");
dbName = "abcd";//p.getProperty("connection.db");
String dbUrl = "jdbc:mysql://" + host + ":" + port + "/"+ dbName + "";
//Logger.d(Logger.MOD_DB, "initializing... DB : " + dbUrl);
System.out.println(dbUrl);
Class.forName(driver).newInstance();
mConnection = DriverManager.getConnection(dbUrl, username,
password);
在函数中调用连接时
try {
conn = ShareConnection.getConnection();
if (conn != null)
System.out.println("Database connected");
else
{
System.out.println("Database connection failed");
return "0";
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
不建议使用自动重新连接解决方案,请提出如何使用连接的建议,以便我能够解决其他问题。