make QueryResult AutoClosable

This allows QueryResults to be used within a try() block without
explicitely closing them.

(cherry picked from commit ad76e0e311)
This commit is contained in:
EoD 2025-07-22 20:32:24 +00:00 committed by github-actions[bot]
parent 675bf7e486
commit 2c3512da8a

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);
}
}
}
}
}