ExecuteBatch方法在java中返回值为-2的数组 [英] ExecuteBatch method return array of value -2 in java

查看:326
本文介绍了ExecuteBatch方法在java中返回值为-2的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在java中执行executeBatch方法时,它返回一个很好的int数组,但是所有数组元素的值都是-2,

When I am executing executeBatch method in java, its returning an int array that's fine but the value is -2 of all array elements,

它应该是0或者+ ve数字显示受影响的行数,
但返回-2,

it should be 0 or +ve number that shows number of rows affected, but its returning -2,

当我在数据库中检查所有更新成功完成时。
请解释这-2的含义以及我如何找到受影响的行数。

when I checked it in database all updates done successful. please explain what is the meaning of this -2 and how I find number of rows affected.

谢谢,
Deepesh Uniyal

Thank, Deepesh Uniyal

推荐答案

jdbc-spec对批量更新的返回代码有如下说明:

The jdbc-spec has the following to say about the return-code of batch-updates:


■0或更高 - 命令已成功处理,值为
更新计数,表示数据库中受
影响的行数命令执行
第14章批量更新121

■ 0 or greater — the command was processed successfully and the value is an update count indicating the number of rows in the database that were affected by the command’s execution Chapter 14 Batch Updates 121

■Statement.SUCCESS_NO_INFO - 命令处理成功,
但受影响的行数未知

■ Statement.SUCCESS_NO_INFO — the command was processed successfully, but the number of rows affected is unknown

Statement.SUCCESS_NO_INFO被定义为-2,所以你的结果说一切正常,但你不会得到有关数字的信息更新列。

Statement.SUCCESS_NO_INFO is defined as being -2, so your result says everything worked fine, but you won't get information on the number of updated columns.

oracle文档说明:

The oracle-documentation states:



准备好了语句批处理,不可能通过批处理中的每个单独语句知道数据库中受影响的行数。因此,所有数组元素的值都为-2。根据JDBC 2.0规范,值-2表示操作成功但受影响的行数未知。

• For a prepared statement batch, it is not possible to know the number of rows affected in the database by each individual statement in the batch. Therefore, all array elements have a value of -2. According to the JDBC 2.0 specification, a value of -2 indicates that the operation was successful but the number of rows affected is unknown.


对于通用语句批处理,该数组包含实际更新计数,指示每个操作影响的行数。实际的更新计数只能在Oracle标准批处理实现中的通用语句的情况下提供。

• For a generic statement batch, the array contains the actual update counts indicating the number of rows affected by each operation. The actual update counts can be provided only in the case of generic statements in the Oracle implementation of standard batching.


对于可调用语句批处理,服务器总是返回值1作为更新计数,而不管每个操作影响的行数。

• For a callable statement batch, the server always returns the value 1 as the update count, irrespective of the number rows affected by each operation.

所以看来如果你需要update-counts你不能使用 PreparedStatement s但是必须回到普通的 Statement s。

So it seems if you need the update-counts you can't use PreparedStatements but have to fall back to plain Statements.

这篇关于ExecuteBatch方法在java中返回值为-2的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆