Spring jdbc 批量修改

时间:2014-11-19 02:24:51   收藏:0   阅读:270

public int[] updateBatchByjdbc(final List<String[]> ids) {
        int[] updateCounts = this.getJdbcTemplate().batchUpdate(
                "update CS_ORDER set AUDIT_STATUS=? where id = ?",
                new BatchPreparedStatementSetter() {

                    @Override
                    public void setValues(PreparedStatement ps, int i)
                            throws SQLException {
                        ps.setString(1, ids.get(i)[0]);
                        ps.setString(2, ids.get(i)[1]);
                    }

                    @Override
                    public int getBatchSize() {
                        return ids.size();
                    }
                });
        return updateCounts;
    }

i=getBatchSize()  //决定循环次数

原文:http://my.oschina.net/u/1778309/blog/346057

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!