Периодически возникает ошибка: No operations allowed after connection closed
В Telegram боте периодически возникает ошибка No operations allowed after connection closed. Ниже один из методов где происходит подключение к БД
public boolean checkIdDb (Update update) {
try {
//в update текст
if (update.hasMessage()) {
//ты куратор?
if (update.getMessage().getChatId().toString().equals(curatorId)) return true;
//ты студент?
Class.forName("com.mysql.cj.jdbc.Driver");
TestConnection.statement.executeUpdate("USE datagroup5m;");
ResultSet resultSet = TestConnection.statement.executeQuery("SELECT * FROM allgrouplist;");
while (resultSet.next()) {
if (resultSet.getString(6).equals(update.getMessage().getChatId().toString())) return true;
}
}
//в update клавиатура
else if (update.hasCallbackQuery()) {
//ты куратор?
if (update.getCallbackQuery().getMessage().getChatId().toString().equals(curatorId)) return true;
//ты студент?
Class.forName("com.mysql.cj.jdbc.Driver");
TestConnection.statement.executeUpdate("USE datagroup5m;");
ResultSet resultSet = TestConnection.statement.executeQuery("SELECT * FROM allgrouplist;");
while (resultSet.next()) {
if (resultSet.getString(6).equals(update.getCallbackQuery().getMessage().getChatId().toString()))
return true;
}
}
} catch (ClassNotFoundException | SQLException exe) {
exe.printStackTrace();
}
//ну тогда пока
return false;
}
Код класса TestConnection через который происходит подключение
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class TestConnection {
public static final String USER_NAME = "root";
public static final String PASSWORD = "password";
public static final String URL = "jdbc:mysql://localhost:3306/datagroup5m";
public static Statement statement;
public static Connection connection;
static {
try {
connection = DriverManager.getConnection(URL, USER_NAME, PASSWORD);
} catch (SQLException exe) {
exe.printStackTrace();
throw new RuntimeException();
}
}
static {
try {
statement= connection.createStatement();
} catch (SQLException exe) {
exe.printStackTrace();
throw new RuntimeException();
}
}
}
Ну и скин возникающей ошибки. Извините что скрином, не успел скопировать сам текст. Следующая ошибка возникает 1-2 раза в сутки. Бот залит и работает на сервере
