import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
/**
* 添加
*/
public int addWxd(final Wxd wxd) {
String sql = "insert into spjkwxd (xh,fxsj,fsdw) values (?,?,?)";
int i = this.jdbcTemplate.update(sql, new PreparedStatementSetter() {
public void setValues(PreparedStatement ps) throws SQLException {
ps.setString(1, wxd.getXh());
ps.setString(2, wxd.getFxsj());
ps.setString(3, wxd.getFsdw());
}
});
return i;
}
/**
* 修改
*/
public void updateWxd(final Wxd wxd) {
String sql = "update spjkwxd set fxsj = ?,fsdw = ? where xh = ?";
this.jdbcTemplate.update(sql, new PreparedStatementSetter() {
public void setValues(PreparedStatement ps) throws SQLException {
ps.setString(1, wxd.getFxsj());
ps.setString(2, wxd.getFsdw());
ps.setString(3, wxd.getXh());
}
});
}
/**
* 删除维修单
*/
public int deleteWxd(String xh) {
String sql = "delete from spjkwxd where xh = '" + xh + "'";
int i = this.jdbcTemplate.update(sql);
return i;
}
Spring的JdbcTemplate对数据库的增删改操作(备忘)
Spring JDBC操作示例
最新推荐文章于 2025-12-01 16:42:02 发布
本文提供了一个使用Spring框架中JDBC模板进行数据库增删改操作的示例代码。包括添加、更新和删除记录的具体实现方式。
873

被折叠的 条评论
为什么被折叠?



