java - Spring批处理在JdbcBatchItemWriter中调用getNextException()

标签 java spring spring-batch

我们有一个带有 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/

相关文章:

java - Spring Boot批量读取/验证不同格式的多个csv文件

java - 在 Maven 中设置外部依赖关系的最佳方法

c# - 如何在 Java 中编写泛型方法

java - 升级到 java 1.8 后,查询未在控制台中打印。 Hibernate版本是5,jboss是7

java - Spring Boot中的转义转义字符

java - 如何使用 Spring Boot Batch Job 更新数据库中的海量数据

java - JSplitPane 调整光标大小

java - Spring 和 Servlet 3.0 Java 配置困惑

java - Spring 启动 : Is there a similar way to hold an XML resource of strings and reference them like in Androids framework?

java - 使用 Java Config 时的 Spring Batch 表前缀