Merge pull request #99 from EoD/make-queryresult-autoclosable

make QueryResult AutoClosable
This commit is contained in:
mlus 2025-07-29 18:35:47 +08:00 committed by GitHub
commit 7a3363592e
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);
}
}
}
}
}