diff --git a/src/main/java/vip/fubuki/playersync/util/JDBCsetUp.java b/src/main/java/vip/fubuki/playersync/util/JDBCsetUp.java index 033c034..afff3fd 100644 --- a/src/main/java/vip/fubuki/playersync/util/JDBCsetUp.java +++ b/src/main/java/vip/fubuki/playersync/util/JDBCsetUp.java @@ -49,7 +49,7 @@ public class JDBCsetUp { Connection connection = getConnection(); // With database selected (and "USE" already run) PreparedStatement queryStatement = connection.prepareStatement(sql); ResultSet resultSet = queryStatement.executeQuery(); - return new QueryResult(connection, resultSet); + return new QueryResult(connection, queryStatement, resultSet); } /** @@ -94,7 +94,7 @@ public class JDBCsetUp { } } - public record QueryResult(Connection connection, ResultSet resultSet) implements AutoCloseable { + public record QueryResult(Connection connection,PreparedStatement preparedStatement, ResultSet resultSet) implements AutoCloseable { @Override public void close() { if (resultSet != null) { @@ -105,6 +105,14 @@ public class JDBCsetUp { } } + if (preparedStatement != null) { + try { + preparedStatement.close(); + } catch (SQLException e) { + LOGGER.error("Error closing PreparedStatement", e); + } + } + if (connection != null) { try { connection.close();