各位大虾:
sql="delete from tbl_test where mytype=?";
PreparedStatement ps= conn.prepareStatement(sql);
ps.setString(1,"abc");
ps.addBatch();
int a= ps.executeBatch();
我的delete from tbl_test where mytype='abc'应该有5条数据被删除,可为何
此处 a.length 的值确为 1
executeBatch()返回的不是实际执行语句的结果吗? 谢谢
sql="delete from tbl_test where mytype=?";
PreparedStatement ps= conn.prepareStatement(sql);
ps.setString(1,"abc");
ps.addBatch();
int a= ps.executeBatch();
我的delete from tbl_test where mytype='abc'应该有5条数据被删除,可为何
此处 a.length 的值确为 1
executeBatch()返回的不是实际执行语句的结果吗? 谢谢
解决方案 »
- 为什么我用java做的界面刚开始只能显示部分组件,过一下才能完全显示
- 静态变量和成员变量,还有私有变量,到底怎么区分?
- 要求写一个正则表达式
- 新手第一个程序就运行错误
- 关于一个算法问题,总是造成死循环了
- [新手]在面板上排列文字???
- 文件传输出现无限循环
- 初学java;请问:我用eclipse,已经安装了java3d的包,但引用java3d的程序却是叉,不知是什么问题,请高手帮忙,谢谢!!
- Apache2.0版本在httpd.conf中载入mod_jk.dll,为何总是提示“找不到指定的模块”
- 我的任务管理器里的javaw.exe和jrun.exe老是去不掉,关不了进程。。。。。。。。。。。。。
- 菜鸟提问:java中据说Double对象不能够相加但是,我对其进行相加却没错误,不知道为什么
- java获取当前系统日期与时间的问题
每个元素才是对应命令update记录 的数量
int[] executeBatch()
throws SQLException
Submits 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
A driver is not required to implement this method. 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 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.3
用a[0]取出是-2?
如何取得我删除的记录数?
谢谢
用executeBatch()是不是没有办法获得?只能用executeupdate()?
System.out.println(a[0]);
怎么回事?
可以看這里http://blog.csdn.net/elimago/archive/2007/07/03/1676516.aspx
Oracle does, they return -2 for updates in executeBatch which iBATIS translates to 0. Oracle
just doesn't return the number of rows being updated for prepared statements.>From the Oracle 9i documentation: "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."