我们有一个带有 Spring Boot 和 Spring Batch 的小批量项目。
我们正在将 JdbcBatchItemWriter
与 db2 数据库结合使用。但是,当发生错误时,我们收到以下错误消息:
Caused by: com.ibm.db2.jcc.am.BatchUpdateException: [jcc][t4][102][10040][3.63.123] Batch failure. The batch was submitted, but at least one exception occurred on an individual member of the batch. Use getNextException() to retrieve the exceptions for specific batched elements. ERRORCODE=-4229, SQLSTATE=null
不幸的是,为了获得清晰的错误消息,我需要 spring 调用 getNextException()
来获取有关精确异常的详细信息。但是,我检查了 SQLErrorCodeSQLExceptionTranslator 类的代码,看起来 Spring 没有为此提供一些功能。
是否有人在不重写类 SQLErrorCodeSQLExceptionTranslator
的情况下找到了此问题的解决方案?
最佳答案
这可以通过在 jobLauncher.run() 结束后检查 getAllFailureExceptions() 返回的异常列表来处理。
List<Throwable> exceptions = execution.getAllFailureExceptions();
for (Throwable throwable : exceptions) {
//code to handle nested exceptions
}
关于java - Spring批处理在JdbcBatchItemWriter中调用getNextException(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31456215/