【问题标题】:UnableToExecuteStatementException: Batch entry was aborted. Call getNextException to see the causeUnableToExecuteStatementException:批处理条目已中止。调用 getNextException 查看原因
【发布时间】:2017-01-02 04:25:47
【问题描述】:

使用@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 来查看原因。此外,我可以直接在数据库中运行 SQL 命令就好了。

知道如何找出原因或问题可能是什么吗?

【问题讨论】:

    标签: java sql


    【解决方案1】:

    我刚刚在 Hibernate 和 Postgres 中看到了类似的情况。据我了解,问题出在 PostgreSQL 驱动程序 (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是一个很奇怪的数字。重要的是它是列数的倍数。

    异常发生

    at org.postgresql.core.v3.QueryExecutorImpl.sendParse(QueryExecutorImpl.java:1329)
    

    这是

    pgStream.SendInteger2(params.getParameterCount()); // # of parameter types specified
    

    这是什么意思?

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

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

    【讨论】:

      【解决方案2】:

      我发现使用 DataPipeline CopyActivity 从 Aurora (MySQL) 导入 Redshift 时遇到类似问题。 我能够通过将传入数据转换为 insertQuery 中的正确目标表类型来解决它,如下所示:

      INSERT INTO my_table (id, bigint_col, timestamp_col) VALUES (?,cast(? as bigint),cast(? as timestamp))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-05-03
        • 2013-03-28
        • 2021-06-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多