标签: 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);
}