DAO`
protected int[] batchExcute(final String sql, final List<Object[]> args) {
int[] temp=jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] os = args.get(i);
for (int n = 0; n < os.length; n++) {
ps.setObject(n + 1, os[n]);
}
}
@Override
public int getBatchSize() {
return args.size();
}
});
return temp;
}
`
//首先设置自动为关闭
jdbcTemplate.getDataSource().getConnection().setAutoCommit(false);
//批处理code
//…
jdbcTemplate.getDataSource().getConnection().commit();//手动提交
jdbcTemplate.getDataSource().getConnection().setAutoCommit(true);//还原
如以上处理报错,可以考虑将getConnection()赋给一个conn变量,后续使用conn操作