try-with-resource (Autoclosable). Connection, PreparedStatement ResultSet Autoclosable, .
stmt.setInt(1, user) , . ( ) try-with-resource!
. try-with-resource!
try (Connection conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS)) {
executeStatement(conn);
} catch (SQLException e) {
String error = "SQLException: " + e.getMessage() + "\nSQLState: " + e.getSQLState() + "\nVendorError: " + e.getErrorCode();
return false;
}
private void executeStatement(Connection con) throws SQLException {
try (PreparedStatement stmt = conn.prepareStatement("SELECT id FROM users WHERE id=? LIMIT 1")) {
stmt.setInt(1, user);
try (ResultSet rs = stmt.executeQuery()) {
}
}
}
( , SQL , . , , PreparedStatement, -resource. ).