现状:我使用preparedStatement.executeBatch()批量插入数据,可这些数据源中可能夹杂着主键冲突,
例如,我批量插入50条数据,可这50条中第10,20,30,40条数据都是主键冲突,我如何捕捉到这4条数据,
目前catch到的好像只是最后一条主键冲突的数据,也就是第40条。
请问高人如何解决。 for(Vo vo : voList) {
if (50 <= intCommitCount) {
try {
pstmt.executeBatch();
} catch (SQLException e) { log.error(e.getMessage());//这边只能获取第40条的主键冲突,请问如何获取10,20,30,40的错误数据
if (e.getErrorCode() == 1062) {
result = RETURN_DUPLICATE_ERROR;
}
}
con.commit();
intCommitCount = 0;
}
intCommitCount++; pstmt.setInt(1, vo.getParam1()); pstmt.addBatch();
}
例如,我批量插入50条数据,可这50条中第10,20,30,40条数据都是主键冲突,我如何捕捉到这4条数据,
目前catch到的好像只是最后一条主键冲突的数据,也就是第40条。
请问高人如何解决。 for(Vo vo : voList) {
if (50 <= intCommitCount) {
try {
pstmt.executeBatch();
} catch (SQLException e) { log.error(e.getMessage());//这边只能获取第40条的主键冲突,请问如何获取10,20,30,40的错误数据
if (e.getErrorCode() == 1062) {
result = RETURN_DUPLICATE_ERROR;
}
}
con.commit();
intCommitCount = 0;
}
intCommitCount++; pstmt.setInt(1, vo.getParam1()); pstmt.addBatch();
}
int[] count = pstmt.executeBatch();
if(pstmt.EXECUTE_FAILED == count[i]) {
....
}