[Demonstration 1]

[Buggy Method]
private static void closeQuietly(Statement statement) {
    if (statement == null)
        return;
    try {
        Connection connection = statement.getConnection();
        statement.close();
        closeQuietly(connection);
    } catch (Exception e) {
        // ignore it
    }
}

[Buggy Hunk]
private static void closeQuietly (Statement statement)

[Patch]
private void closeQuietly (Statement statement)

[Demonstration 2]

[Buggy Method]
public static void deleteDepartment(int id) {
    Connection connection = null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        System.out.println("Драйвер подключен");
        connection = DriverManager.getConnection(url, user, pass);
        System.out.println("Соединение установлено");
        Statement statement;
        statement = connection.createStatement();
        statement.executeQuery("DELETE FROM department WHERE department_id=" + id);
    } catch (Exception ex) {
        //выводим наиболее значимые сообщения
        Logger.getLogger(Interaction.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException ex) {
                Logger.getLogger(Interaction.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

[Buggy Hunk]
statement.executeQuery("DELETE FROM department WHERE department_id=" + id);

[Patch]
statement.executeUpdate("DELETE FROM department WHERE department_id=" + id);

[Demonstration 3]

[Buggy Method]
@Override
public int addContact(final Contact contact) throws DalException {
    int contactId;
    // Key to hold id value
    KeyHolder idKey = new GeneratedKeyHolder();
    try {
        jdbcTemplate.update(new PreparedStatementCreator() {

            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement addContactStmt = connection.prepareStatement("INSERT INTO Contact (FullName, Nickname, Notes) VALUES (?,?,?)");
                addContactStmt.setString(1, contact.getFullName());
                addContactStmt.setString(2, contact.getNickname());
                addContactStmt.setString(3, contact.getNotes());
                return addContactStmt;
            }
        }, idKey);
        contactId = idKey.getKey().intValue();
    } catch (DataAccessException ex) {
        throw new DalException(ex);
    }
    return contactId;
}

[Buggy Hunk]
PreparedStatement addContactStmt = connection.prepareStatement("INSERT INTO Contact (FullName, Nickname, Notes) VALUES (?,?,?)");

[Patch]
PreparedStatement addContactStmt = connection.prepareStatement("INSERT INTO Contact (FullName, Nickname, Notes) VALUES (?,?,?)", Statement.RETURN_GENERATED_KEYS);