首页 > 代码库 > BatchPreparedStatementSetter,用法
BatchPreparedStatementSetter,用法
spring批量更新数据 ---- BatchPreparedStatementSetter
(2007-04-15 15:41:29)标签:
springbatchpreparedstatementsetter |
分类: spring |
public void batchInsertRows(String sql,final List<Object[]> dataSet) throws Exception{
BatchPreparedStatementSetter setter=new BatchPreparedStatementSetter(){
public int
getBatchSize(){
return
dataSet.size();
}
public void
setValues(PreparedStatement ps,int i){
Object[] obj
= dataSet.get(i);
int nextId =
getNextId();
try{
ps.setLong(1,nextId);
ps.setLong(2,Integer.parseInt(obj[0].toString()));
ps.setLong(3,Integer.parseInt(obj[1].toString()));
ps.setString(4,(String)obj[2]);}
catch(Exception
e){
e.printStackTrace();
}
}
};
jdbcTemplate.batchUpdate(sql,setter);
}
BatchPreparedStatementSetter,用法