利用SimpleJdbcTemplate进行增删改查
来源:互联网 发布:java架构师岗位职责 编辑:程序博客网 时间:2024/06/18 13:07
private SimpleJdbcTemplate simpleJdbcTemplate; //查询实体对象: public AdPostInfoBean selectByKey(int apId, int targetId, int targetType) { String sql = "select * from adpostinfo where apid=? and targetid=? and targettype=?"; try { return this.simpleJdbcTemplate.queryForObject(sql, ParameterizedBeanPropertyRowMapper .newInstance(AdPostInfoBean.class), apId, targetId, targetType); } catch (EmptyResultDataAccessException e) { return null; } } //查询列表 public List<AdPostInfoBean> selectByApid(int apId) { String sql = "select * from adpostinfo where apid=?"; return this.simpleJdbcTemplate.query(sql, ParameterizedBeanPropertyRowMapper .newInstance(AdPostInfoBean.class), apId); } //删除 public int deleteByApId(int apId) { String sql = "delete from adpostinfo where apid=?"; return this.simpleJdbcTemplate.update(sql, apId); } //添加 public int insert(AdPlayInfoBean adPlayInfo){ String sql = "insert into adplayinfo (APID, PBID, ModifyTime, Status) values (:apId, :pbId, :modifytime, :status)"; KeyHolder keyHolder = new GeneratedKeyHolder(); this.simpleJdbcTemplate.getNamedParameterJdbcOperations().update( sql, new BeanPropertySqlParameterSource(adPlayInfo), keyHolder ); return keyHolder.getKey().intValue(); } //普通修改 public int updateStatusByPbId(int pbId, int oldStatus, int newStatus){ String sql = "update adplayinfo set Status = ? where pbId = ? and Status = ?"; return this.simpleJdbcTemplate.update(sql, newStatus, pbId, oldStatus); } //批量修改 public int[] update(List<AdPostInfoBean> adPostInfos) { if (adPostInfos == null) return new int[] {}; String sql = "update adpostinfo set postuser:=postuser,posttime=:posttime,poststatus=:poststatus" + " where apid=:apid and targetid=:targetid and targettype=:targettype"; return this.simpleJdbcTemplate.batchUpdate(sql, SqlParameterSourceUtils .createBatch(adPostInfos.toArray())); } //查询表数量 public int getUsedRotateTime(int pbid){ StringBuffer sqlbuf = new StringBuffer("select sum(Length) from ADDataRotator a" + " join ADPlanRotator b on a.apid = b.apid" + " join ADPlayInfo c on c.apid = b.apid where 1=1"); sqlbuf.append(" and a.ADType = ").append(PlayTaskType.video); sqlbuf.append(" and c.status > 0 and b.RotatorCycle > 0 and c.PBID = ?"); String sql = sqlbuf.toString(); try{ return this.simpleJdbcTemplate.queryForInt(sql, pbid); } catch (EmptyResultDataAccessException e) { return 0; } }
0 0
- 利用SimpleJdbcTemplate进行增删改查
- 利用SimpleJdbcTemplate进行增删改查
- 利用SimpleJdbcTemplate进行增删改查
- 利用DataList控件进行增删改查
- 利用PreparedStatement进行增删改查!
- 利用hibernate进行增删改查
- 利用java反射对数据库进行增删改查
- 利用Solrj对索引进行增删改查
- JDBC 1 利用Statement对数据库进行增删改查
- XML利用dom4j进行增删查改等方法
- Hibernate进行增删查改
- mybatis利用注解实现增删改查
- java 利用数组实现增删改查
- 使用hibernate进行增删改查
- JS对数据库进行增删改查
- ibatis使用sql进行增删改查
- jndi操作Ldap进行增删改查
- YII进行数据增删改查分析
- js实现动态控件提示信息模版
- Linux内核——第十五章:页高速缓存
- 不在同一个内网的本机通过SecureCrt配置,访问服务器的应用(应用设置仅允许内网之间能访问)
- Python实现bgp.he.net网站接口查询
- js判断开始时间不能小于结束时间
- 利用SimpleJdbcTemplate进行增删改查
- HihoCoder#1082 : 然而沼跃鱼早就看穿了一切
- apache htdocs 的路径
- 神器3.0时代,几乎所有的 LBS 社交应用
- Android TouchEvent事件传递机制
- 单一职责原则
- .net项目中使用log4net记录日志
- Spring3核心技术之JdbcTemplate
- 酒桌上的计算机网络