0

我正在使用 Spring 3.1.2,正在使用 PreparedStatementSetter 进行选择、更新和插入,但是如何用于删除查询?

4

2 回答 2

1

jdbcTemplate.update() can be used for delete's

e.g.

JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.update("delete from my_table where value=? ", new PreparedStatementSetter() {
  public void setValues(PreparedStatement ps) throws SQLException {
    ps.setLong(1, 2L);//or setString or whatever
  }
});

you can also execute a delete without the PreparedStatementSetter as shown here: http://www.java2s.com/Code/Java/Spring/UseJdbcTemplateToExecuteDeleteStatementWithParameter.htm

于 2013-10-09T09:34:14.527 回答
0

您可以PreparedStatement像这样用于删除

String sql = "DELETE FROM MY_TABLE WHERE ID = ?";
PreparedStatement ps = yourDBConnection.prepareStatement(sql);
ps.setInt(1, 1001);

// execute delete SQL stetement
ps.executeUpdate();
于 2013-10-09T06:46:11.413 回答