数据库批量操作时报错,经常无法定位到具体是那条记录导致的;方法是 捕获异常后,再遍历数据集,单条执行,再次捕获异常,这样就容易找到异常的原因l。
try {
long beginTime2 = System.currentTimeMillis();
lmdsYxLkjRealService.updateBatchById(realInfoList);
log.info("real表批量更新耗时:"+(System.currentTimeMillis() - beginTime2) +"毫秒,更新条数:"+realInfoList.size());
}catch(Exception e){
log.error("real表批量更新出错了:"+e.getMessage(),e);
for(LmdsYxLkjReal object:realInfoList){
try {
lmdsYxLkjRealService.updateById(object);
}catch(Exception e1){
log.error("object id = " + object.getId() + ";" + object.getLocoTypeid() + "-" + object.getLocoNo() + "-" + object.getAbj());
log.error("原始数据包是:"+object.getSrcDataHexStr());
}
}
}