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:
parent
675bf7e486
commit
2c3512da8a
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user