JDBCTemplate操作
@Repositorypublic class MemberDao { private JdbcTemplate template; @Resource(name="dataSource") public void setDataSource(DataSource dataSource){ template = new JdbcTemplate(dataSource); } public List select(){ return template.query("select * from t_member", new RowMapper(){ @Override public Member mapRow(ResultSet rs, int rowNum) throws SQLException { Member m = new Member(); m.setId(rs.getLong("id")); m.setName(rs.getString("name")); return m; } }); } public int insert(String name) throws Exception{ return template.update("insert into t_member(name) values(?)",name); } public int delete(long id) throws Exception{ return template.update("delete from t_member where id = ?",id); } public int update(long id,String name) throws Exception{ return template.update("update t_member set name = ? where id = ?",name,id); } }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~