jdbc的executeBatch()返回正确的行计数

如果你想让你的JDBC驱动从executeBatch()返回正确的行计数,那么将此属性设为true(开启这个选项通常是安全请问具体怎么实现呢如果你的sql正常执行的话都会... 如果你想让你的JDBC驱动从executeBatch()返回正确的行计数 , 那么将此属性设为true(开启这个选项通常是安全 请问具体怎么实现呢
如果你的sql正常执行的话 都会返回-2 你可懂哈
展开
 我来答
jdw831209
推荐于2016-05-14 · TA获得超过111个赞
知道答主
回答量:118
采纳率:0%
帮助的人:36.7万
展开全部
String sql="sql内容";
int[] i=statement.executeBatch(sql);
//试试看我也不是很懂
将一批命令提交给数据库来执行,如果全部命令执行成功,则返回更新计数组成的数组。返回数组的 int
元素的排序对应于批中的命令,批中的命令根据被添加到批中的顺序排序。方法 executeBatch
返回的数组中的元素可能为以下元素之一:
1.大于等于 0 的数 - 指示成功处理了命令,是给出执行命令所影响数据库中行数的更新计数
2.SUCCESS_NO_INFO 的值 - 指示成功执行了命令,但受影响的行数是未知的
如果批量更新中的命令之一无法正确执行,则此方法抛出 BatchUpdateException,并且 JDBC
驱动程序可能继续处理批处理中的剩余命令,也可能不执行。无论如何,驱动程序的行为必须与特定的 DBMS
一致,要么始终继续处理命令,要么永远不继续处理命令。如果驱动程序在某一次失败后继续进行处理,则
BatchUpdateException.getUpdateCounts
方法返回的数组将包含的元素与批中存在的命令一样多,并且其中至少有一个元素将为:
3.EXECUTE_FAILED 的值 - 指示未能成功执行命令,仅当命令失败后驱动程序继续处理命令时出现
bd9006
2012-10-09 · TA获得超过2.5万个赞
知道大有可为答主
回答量:4.8万
采纳率:63%
帮助的人:1.6亿
展开全部
没写明白是什么问题。

executeBatchint[] executeBatch()
throws SQLExceptionSubmits a batch of commands to the database for execution and
if all commands execute successfully, returns an array of update counts.
The int elements of the array that is returned are ordered
to correspond to the commands in the batch, which are ordered
according to the order in which they were added to the batch.
The elements in the array returned by the method executeBatch
may be one of the following:

A number greater than or equal to zero -- indicates that the
command was processed successfully and is an update count giving the
number of rows in the database that were affected by the command's
execution

A value of SUCCESS_NO_INFO -- indicates that the command was
processed successfully but that the number of rows affected is
unknown

If one of the commands in a batch update fails to execute properly,
this method throws a BatchUpdateException, and a JDBC
driver may or may not continue to process the remaining commands in
the batch. However, the driver's behavior must be consistent with a
particular DBMS, either always continuing to process commands or never
continuing to process commands. If the driver continues processing
after a failure, the array returned by the method
BatchUpdateException.getUpdateCounts
will contain as many elements as there are commands in the batch, and
at least one of the elements will be the following:

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

The possible implementations and return values have been modified in
the Java 2 SDK, Standard Edition, version 1.3 to
accommodate the option of continuing to proccess commands in a batch
update after a BatchUpdateException obejct has been thrown.
Returns:an array of update counts containing one element for each
command in the batch. The elements of the array are ordered according
to the order in which commands were added to the batch.
Throws:SQLException - if a database access error occurs,
this method is called on a closed Statement or the
driver does not support batch statements. Throws BatchUpdateException
(a subclass of SQLException) if one of the commands sent to the
database fails to execute properly or attempts to return a result set.Since:1.3See Also:addBatch(java.lang.String),
DatabaseMetaData.supportsBatchUpdates()
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
hghlghy
2012-10-15
知道答主
回答量:6
采纳率:0%
帮助的人:3.4万
展开全部
求源代码.......look、、、
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
sudanbonze
2012-10-09
知道答主
回答量:15
采纳率:0%
帮助的人:7.3万
展开全部
不用开启,默认就会返回的啊!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式