Spring的JdbcTemplate对数据库的增删改操作(备忘)
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; }
相关推荐
adsadadaddadasda 2020-08-19
yongyoumengxiang 2020-08-02
thunderstorm 2020-06-06
幸运小侯子 2020-05-25
白净垃圾桶 2020-05-02
csuzxm000 2020-01-08
空杯心态虚怀若谷 2012-08-24
JudeJoo 2019-07-01
seawaycao 2019-07-01
cyAspNet 2019-07-01
tangxiong0 2019-07-01
xiaoxiangyu 2019-06-30
剑铭 2015-07-13
oxuzhenyi 2014-08-20
愤怒的砖头 2013-10-11
longdan0 2013-07-30