8

有人可以指出我以下 Spring Jdbc 模板代码中的任何错误吗?

当我单击删除时,记录没有被删除,也没有显示错误。

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);
}
4

2 回答 2

16

这是一个例子。注意:

整数 ID

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

    return jdbcTemplate.update(sql, args) == 1;
}
于 2017-07-14T20:45:28.633 回答
0
@Override
    public String deleteXXById(String id) {
        String sql = "DELETE FROM VENUE WHERE id =:id?";
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("id", id);

        Object[] args = new Object[] {id};
        int update = jdbcTemplate.update(sql, paramMap);
        String updatecount = "Failed";
        if (update == 0) {
            updatecount = "Failed";
        } else {
            updatecount = "SUCCESS";
        }
         return updatecount;
    }
于 2019-03-08T13:42:04.333 回答