Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JdbcTemplate delete syntax

Can someone point out any mistake in my following code of Spring Jdbc Template?

When I click delete, the record is not getting deleted and there are no errors showing.

public void delete(String id) {
    logger.debug("Deleting existing person");

    // Prepare our SQL statement using Unnamed Parameters style
    String query = "delete from person where id = ?";

    // Assign values to parameters
    Object[] person = new Object[] {id};

    // Delete
    jdbcTemplate.update(query, person);
}
like image 702
amzi Avatar asked Aug 15 '13 19:08

amzi


1 Answers

Here is an example. Pay attention:

Integer id

public boolean delete(Integer id){
    String sql = "DELETE FROM organization WHERE id = ?";
    Object[] args = new Object[] {id};

    return jdbcTemplate.update(sql, args) == 1;
}
like image 103
Kirill Ch Avatar answered Sep 20 '22 17:09

Kirill Ch