将 JDBC 批量插入发送到 crate.io 时,return 值 -3 表示什么

What does return value -3 indicate when sending a JDBC bulk insert to crate.io

我尝试使用 JDBC 对 Crate 实例进行批量插入:

    for(...) {
        statement.setLong(1, startTime);
        statement.setInt(2, i);
        ...
        statement.addBatch();
    }

    results = uaStatement.executeBatch();
    logger.info("Had bulk-result: " + Arrays.toString(results));

生成的 int[] 数组应包含 0 或 1,具体取决于是否插入了该行。

但我得到了很多“-3”,JDBC 标准和文档似乎都没有定义。

返回-3 时似乎没有插入行,但看不到其他错误信息。似乎 -3 直接来自 Crate 服务器,客户端 JDBC 实现只是转发它。

这是板条箱 2.3.3,带有 JDBC 驱动程序 2.2.0

compile 'io.crate:crate-jdbc:2.2.0'

这说明什么?发送的值有问题吗?

Had bulk-result: [1, 1, 1, 1, -3, -3, -3, -3, -3, -3, 1, -3, -3, -3, -3, -3, -3, ...

请查看 java.sql.BatchUpdateException 的 API 文档(强调我的):

After a command in a batch update fails to execute properly and a BatchUpdateException is thrown, the driver may or may not continue to process the remaining commands in the batch. If the driver continues processing after a failure, the array returned by the method BatchUpdateException.getUpdateCounts will have an element for every command in the batch rather than only elements for the commands that executed successfully before the error. In the case where the driver continues processing commands, the array element for any command that failed is Statement.EXECUTE_FAILED.

Statement.executeBatch()

A value of EXECUTE_FAILED -- indicates that the command failed to execute successfully and occurs only if a driver continues to process commands after a command fails

-3 是常量 Statement.EXECUTE_FAILED。在某些驱动程序中,这些执行失败的异常将链接到此 BatchUpdateException(检查 getNextException 或遍历所有可抛出的异常)。

但是,如果所有后续值都报告 Statement.EXECUTE_FAILED,这可能意味着驱动程序实际上并没有尝试执行剩余的参数集,而是简单地报告 Statement.EXECUTE_FAILED 来自第一次失败。在这种情况下,驱动程序应该 'give up' 在第一次失败后只报告成功执行的参数集的更新计数,如 JDBC 规范和 API 文档中所述。