博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
为什么iBatis+Oracle的executeBatch总是返回0?
阅读量:6684 次
发布时间:2019-06-25

本文共 1365 字,大约阅读时间需要 4 分钟。

hot3.png

iBatis+Oracle,调用executeBatch总是返回0,而不是真实的受影响记录数。查看代码:

public class SqlExecutor {  。。。  private static class Batch {     。。。    public int executeBatch() throws SQLException {      int totalRowCount = 0;      for (int i = 0, n = statementList.size(); i < n; i++) {        PreparedStatement ps = (PreparedStatement) statementList.get(i);        int[] rowCounts = ps.executeBatch();        for (int j = 0; j < rowCounts.length; j++) {          if (rowCounts[j] == Statement.SUCCESS_NO_INFO) {            // do nothing          } else if (rowCounts[j] == Statement.EXECUTE_FAILED) {            throw new SQLException("The batched statement at index " + j + " failed to execute.");          } else {            totalRowCount += rowCounts[j];          }        }      }      return totalRowCount;    }

注意标红部分!rowCounts[j] == Statement.SUCCESS_NO_INFO

Oracle手册有说明 "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没有办法知道batch中某语句确切影响的记录数,而JDBC 2.0规范规定,操作成功但影响行数不确定的,返回Statement.SUCCESS_NO_INFO(-2),最终totalRowCount没有累计,一直保持0。

转载于:https://my.oschina.net/avantyao/blog/72987

你可能感兴趣的文章
TypeScript入门知识五(面向对象特性二)
查看>>
TextBox字符串转换为数字类型
查看>>
HTML5的可视化开发工具Maqetta Designer
查看>>
leetcode 29. Divide Two Integers
查看>>
axis调用webservice客户端开发
查看>>
Activiti5第八弹,ProcessEngineConfiguration和ProcessEngine
查看>>
细说C#多线程那些事 - 线程同步和多线程优先级
查看>>
linux下tomcat服务器的启动和关闭以及查看实时打印日志
查看>>
WinForm 数据库无限填充树目录 treeView
查看>>
Add Two Numbers
查看>>
as3 文档类引用
查看>>
NOIp 数据结构专题总结 (1):STL、堆、并查集、ST表、Hash表
查看>>
单例模式
查看>>
SSM + AJAX + JSON 动态下拉框
查看>>
第二阶段冲刺5
查看>>
IE识别
查看>>
发送验证码倒计时
查看>>
程序员看中的浏览器
查看>>
浙大pat甲级题目---1021. Deepest Root (25)
查看>>
CCRD_TOC_2008年第2期
查看>>