`
nesuk
  • 浏览: 167747 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

关于Spring的JdbcTemplate批量更新batchUpdate()方法的返回值为-2的异常

阅读更多
近日在使用JdbcTemplate做大量的数据库数据同步的工作,基本就是“从A库查询数据--生成CSV--解析成SQL插入B库”这样一个过程。因为使用的是JdbcTemplate,所以在将数据导入B库时采用的是“先批量删,再批量插入”的策略。如果B库有相同主键的记录,则会先删掉,然后再将数据批量插入,这样就避免了主键冲突异常。这样更新数据量=删除记录数,新增数据量=总数据量-更新数据量。

但是在使用batchUpdate()函数时遇到了执行结果为-2的问题,先查查API:
batchUpdate

public int[] batchUpdate(String[] sql)
                  throws DataAccessException
Description copied from interface: JdbcOperations
Issue multiple SQL updates on a single JDBC Statement using batching.
Will fall back to separate updates on a single Statement if the JDBC driver does not support batch updates.

Specified by:
batchUpdate in interface JdbcOperations
Parameters:
sql - defining an array of SQL statements that will be executed.
Returns:
[b]an array of the number of rows affected by each statement[/b]
Throws:
DataAccessException - if there is any problem executing the batch



返回值为一个整型的数组,数组的每个元素值对应每条SQL影响的数据库的记录数。
这样无论如何负值也无法理解的。网上查询有地方说是驱动的问题,然后动手用JDBC的PreparedStatement测试了一把,同样的结果。那么说,出现这种结果的根本原因是JDBC驱动。

从Oracle的官网下载了Oracle11gR2的最新驱动ojdbc6.jar,目前问题仍然存在。。。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics