I'm running my JDBC code on sonarqube. There's issue with my code.
try (final Connection connection = DatabaseConnectionProvider.createConnection(configuration)) {
PreparedStatement statement = connection.prepareStatement(
"SELECT 1 FROM `todo_items` WHERE `id` = ? LIMIT 1;");
statement.setLong(1, id);
ResultSet resultSet = statement.executeQuery();
if (!resultSet.next()) {
return false;
}
statement = connection.prepareStatement("UPDATE `todo_items` SET `checked` = ? WHERE id = ?;");
statement.setBoolean(1, checked);
statement.setLong(2, id);
statement.executeUpdate();
return true;
}
It says on line 3 and line 9 there is blocker issue.
"Use try-with-resources or close this "PreparedStatement" in a "finally" clause." I do not understand this.