批处理程序中的 DB2 插入失败(使用 Java 和 DB2)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24824786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 15:02:24  来源:igfitidea点击:

DB2 Insertion failing in a batch program (using Java and DB2)

javadb2batch-processing

提问by Megan

This is the first time I am using DB2 as Database with my Java application. I am writing a batch program and I need to insert into multiple parent - child tables.

这是我第一次在 Java 应用程序中使用 DB2 作为数据库。我正在编写一个批处理程序,我需要插入到多个父-子表中。

The issue I am facing is that the insert into the table is failing giving me the following error:

我面临的问题是插入表失败给我以下错误:

    com.ibm.db2.jcc.am.BatchUpdateException: [jcc][t4][102][10040][3.59.81] 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
                    at com.ibm.db2.jcc.am.dd.a(dd.java:404)
                    at com.ibm.db2.jcc.am.o.a(o.java:365)
                    at com.ibm.db2.jcc.am.cn.a(cn.java:4280)
                    at com.ibm.db2.jcc.am.cn.c(cn.java:4063)
                    at com.ibm.db2.jcc.t4.l.c(l.java:78)
                    at com.ibm.db2.jcc.am.cn.executeBatch(cn.java:2425)

Apart from this error I am not able to find any other error in any of my log files. Kindly provide me some pointers to trace or fix this issue.

除了这个错误,我在我的任何日志文件中都找不到任何其他错误。请为我提供一些跟踪或解决此问题的指示。

回答by AngocA

There are nested exception, and the exception that you are catching is the "top" one. You have to scan the other exceptions via the getNextException in order to detect the error. This is a normal behaviour while using JDBC.

有嵌套异常,您捕获的异常是“顶级”异常。您必须通过 getNextException 扫描其他异常以检测错误。这是使用 JDBC 时的正常行为。

I advise you to have a "while" in the catch part of your method, in order to found the error.

我建议你在方法的 catch 部分有一个“while”,以便找到错误。