spring jdbcTemplate批量更新操作

来源:互联网 发布:php数组在线格式化 编辑:程序博客网 时间:2024/05/23 15:45

直接给代码:

    /**     * 批量保存流程泳道实例     * @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语句都可以执行。

原创粉丝点击