本文介绍了UnableToExecuteStatementException:批量输入已中止。调用getNextException以查看原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 @SqlBatch 批量更新数据库

@SqlBatch("<SQL Command>")
@BatchChunkSize(INSERT_BATCH_SIZE)
void insert(@BindBean Iterator<SomeObj> someObj);

我收到此错误:

org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException:
java.sql.BatchUpdateException:批处理条目0 ...已中止。调用
getNextException查看原因。

问题是被捕获的异常是 UnableToExecuteStatementException 而不是原来的 BatchUpdateException ,所以我无法调用 getNextException 来查看原因。此外,我可以直接在DB中运行SQL命令。

The problem is the exception that's being caught is a UnableToExecuteStatementException and not the original BatchUpdateException, so I am unable to call getNextException to see the cause. Furthermore, I can run the SQL command in the DB directly just fine.

任何想法如何找到问题的根源或问题可能是什么?

Any idea how to get to the bottom of the cause or what the issue might be?

推荐答案

我刚看到Hibernate和Postgres之类的东西。据我所知,问题在于PostgreSQL驱动程序(org.postgresql.core.v3.QueryExecutorImpl)。

I have just seen a thing like that with Hibernate and Postgres. As I understand, the problem is in the PostgreSQL driver (org.postgresql.core.v3.QueryExecutorImpl).

我看到的是:

java.sql.BatchUpdateException: Batch entry 0 INSERT INTO myscheme.table_name (list,of,column,names,...) VALUES (9007199314139196, 'F', 27, 625, 625, 625, 625, 625, 28), (9007199314139198, 'T', 2395, 2369, 2369, 2369, 2369, 2369, 2389), ... was aborted.  Call getNextException to see the cause.

无信息。

我抓住并打印例外,

    } catch(JDBCConnectionException t) {
        System.out.println("================ {{{");
        SQLException current = t.getSQLException();
        do {
           current.printStackTrace();
        } while ((current = current.getNextException()) != null);
        System.out.println("================ }}}");
        throw t;
    }

并得到:

Caused by: java.io.IOException: Tried to send an out-of-range integer as a 2-byte value: 33300

仍然令人困惑。 33300是一个非常奇怪的数字。重要的是它是列数的倍数。

Still confusing. 33300 is a very strange number. What is important is that it is a multiple of the number of columns.

发生异常

at org.postgresql.core.v3.QueryExecutorImpl.sendParse(QueryExecutorImpl.java:1329)
pgStream.SendInteger2(params.getParameterCount()); // # of parameter types specified

这是什么意思?

对于单个INSERT语句,值的总数,即列数乘以行数不得超过32767。

The total number of values, that is, the number of columns multiplied by the number of rows must not exceed 32767 for a single INSERT statement.

您可以将32767除以列数以获得每个SQL INSERT语句的最大行数。

You can divide 32767 by the number of columns to get the maximal number of rows per one SQL INSERT statement.

这篇关于UnableToExecuteStatementException:批量输入已中止。调用getNextException以查看原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 12:17