В моем java скрипте постоянно обрывается соединения с mysql так как одно и тоже приложение обращается к одной базе!
КОД ОШИБКИ:
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: The last packet successfully received from the server was 6,471,540 milliseconds ago. The last packet sent successfully to the server was 6,471,540 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
Подскажите как в данном случае добавить функцию
autoReconnect=true
в мой java код?
public static Connection getMySqlConnection(String host, int port, String database, String user, String password) {
StringBuilder sb = new StringBuilder(host);
if (port >= 0) sb.append(":").append(port);
sb.append("/").append(database);
sb.append("?useSSL=false");
return getMySqlConnection(sb.toString(), user, password);
}
public static String getMySqlUrl(String host, int port, String database) {
StringBuilder sb = new StringBuilder("jdbc:mysql://").append(host);
if (port >= 0) sb.append(":").append(port);
sb.append("/").append(database).append("?useSSL=false");
return sb.toString();
}
public String getDbUrl() {
StringBuilder sb = new StringBuilder("jdbc:");
if (dbUseMySQL()) {
sb.append("mysql://")
.append(dbMySqlUrl())
.append(":").append(dbMySqlPort())
.append("/").append(dbMySqlDatabase())
.append("?useSSL=false");
} else {
sb.append("sqlite:")
.append(dbFileName());
}
return sb.toString();
}
}