加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

spring jdbcTemplate 批量执行SQL语句(update insert delete)

(2016-10-21 15:15:29)
标签:

spring

批量执行

分类: Java
spring jdbcTemplate 批量执行SQL语句(update insert delete)
直接赋上案列代码

   
    public void saveObj(final List list)throws Exception{
        String sql = "insert into t_table(value1,value2,value3,value4,value5) values(?,?,?,?,?)";
        try{
            this.getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter(){
                public int getBatchSize() {
                    return taInstswimwayList.size();
                }
                public void setValues(PreparedStatement pst, int i) throws SQLException {
                    Object obj = (Object ) list.get(i);
                    pst.setString(1, obj.Value1());
                    pst.setObject(2, obj.Value2());
                    pst.setString(3, obj.Value3());
                    pst.setString(4, obj.Value4());
                    pst.setString(5, obj.Value5());
                }
            });
        }catch(Exception e){
            e.printStackTrace();
            throw new Exception(e.getMessage());
        }
    }

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有