我在jdbctemplate中使用batchupdate插入时尝试处理重复键异常.
当我尝试使用重复键插入时,它会在服务方法中使用Exception catch块而不是BatchUpdateException catch块.我将堆栈跟踪作为BatchUpdateException但仍然会进入Exception catch块.任何的想法?
代码如下:
服务类别:
try {
auctionDM.insertSelctedAuctionItem(salesBean, Constants.VESL_CODE);
} catch (BatchUpdateException bue) {
logger.error(" Duplicate item -", bue);
throw new MyException(ExceptionCodes.DB_DUPLICATE_ITEM);
} catch (SQLException se) {
logger.error(" SQL Exception occured -", se);
throw new MyException(ExceptionCodes.DB_ERROR);
} catch (LegacyException e) {
logger.error(" AppException occured -", e);
throw new MyException(ExceptionCodes.DB_ERROR);
} catch (Exception e) {
logger.error(" SystemException occured -", e);
throw new MyException(ExceptionCodes.DB_ERROR);
}
Run Code Online (Sandbox Code Playgroud)
数据管理员类:
public int[] insertSelctedAuctionItem(SalesBean salesBean, String veslCode) throws SQLException {
//code
return getJdbcTemplate().batchUpdate(sqlQuery.toString(), batchParams);
} …
Run Code Online (Sandbox Code Playgroud)