Merge pull request #102 from mlus-asuka/backport-99-to-1.20.4

[Backport 1.20.4] make QueryResult AutoClosable
This commit is contained in:
mlus 2025-07-29 18:40:02 +08:00 committed by GitHub
commit 9880c7e74c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -90,6 +90,24 @@ public class JDBCsetUp {
}
}
public record QueryResult(Connection connection, ResultSet resultSet) {
public record QueryResult(Connection connection, ResultSet resultSet) implements AutoCloseable {
@Override
public void close() {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
LOGGER.error("Error closing ResultSet", e);
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
LOGGER.error("Error closing Connection", e);
}
}
}
}
}