Auto-closed insert ResultSet
This commit is contained in:
parent
c2dcf7ee80
commit
aeb1ca9d3e
@ -79,12 +79,13 @@ public class DatabaseProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int insert(String sql, Object... params) throws SQLException {
|
public int insert(String sql, Object... params) throws SQLException {
|
||||||
try (PreparedStatement query = getConnection().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
try (
|
||||||
|
PreparedStatement query = getConnection().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||||
|
ResultSet rs = query.getGeneratedKeys()
|
||||||
|
) {
|
||||||
resolveParameters(query, params);
|
resolveParameters(query, params);
|
||||||
query.executeUpdate();
|
query.executeUpdate();
|
||||||
|
|
||||||
ResultSet rs = query.getGeneratedKeys();
|
|
||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
return rs.getInt(1);
|
return rs.getInt(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user