在使用mybatis的批量新增出现Statement cancelled due to timeout or client request这个异常.下面代码是使用批量新增的方法:
public void batchUpdate(String str, List objs )throws ServerSqlErrorException{
SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
//批量执行器
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false);
try{
if(objs!=null){
for(int i=0,size=objs.size();i<size;i++){
sqlSession.update(str, objs.get(i));
}
sqlSession.flushStatements();
sqlSession.commit();
sqlSession.clearCache();
}
}catch (Exception e){
throw new ServerSqlErrorException(e);
}finally{
sqlSession.close();
}
}
求解