现在的位置: 首页 > 综合 > 正文

spring jdbcTemplate批量更新操作

2017年12月02日 ⁄ 综合 ⁄ 共 849字 ⁄ 字号 评论关闭

直接给代码:

    /**
     * 批量保存流程泳道实例
     * @param taInstswimwayList 流程泳道实例集合
     */
    public void saveTaInstswimwayObj(final List taInstswimwayList)throws Exception{
        String sql = "insert into ta_instswimway(WAYID,PROCINSTID,WAYNAME,GRAPHMSG,DIRECTION) values(?,?,?,?,?)";
        try{
        	this.getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter(){
				public int getBatchSize() {
					return taInstswimwayList.size();
				}
				public void setValues(PreparedStatement pst, int i) throws SQLException {
					TaInstswimway obj = (TaInstswimway) taInstswimwayList.get(i);
	                pst.setString(1, obj.getWayid());
	                TaProcInst taProcInstObj = obj.getTaProcinst();
	                String procinstid = taProcInstObj.getProcinstid();
	                pst.setObject(2, procinstid);
	                pst.setString(3, obj.getWayname());
	                pst.setString(4, obj.getGraphmsg());
	                pst.setString(5, obj.getDirection());
				}
        	});
        }catch(Exception e){
            e.printStackTrace();
            throw new Exception(e.getMessage());
        }
    }

insert 语句、update语句、delete语句都可以执行。

抱歉!评论已关闭.