mysql jdbc驱动 批量更新,Postgresql中的批量更新JDBC驱动程序在自动提交中回滚

I am doing batch inserts using postgres 9.3-1100-jdbc41 JDBC4 driver.

According to the JDBC specification, its up

to the application to disable autocommit and to commit or

rollback the transaction.

In my case, I am not using any transaction(i.e., auto commit is true) but still the inserts are rolled back if one of the insert in the batch fails.

According to JDBC specification "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.". Here it does not says that previously executed commands will be rolled back.

Is my understanding wrong? If not why driver is behaving in this way and if yes what is the right behavior according to specification.

解决方案

As far as I can tell the spec essentially leaves this up to the driver; it doesn't specify whether or not already-processed work is committed if the batch fails.

PgJDBC executes the batch in a transaction, so if any part of the batch fails then it will all be aborted.

If you feel this behaviour to be incorrect, the first thing you need to do is write a test case demonstrating that other drivers consistently behave a different way to PgJDBC and submit it to the PgJDBC issue tracker. We do not have time to research behaviour of other drivers, so you need to write the test case and run it some other popular databases (MS SQL Server, Oracle, DB2, MySQL, etc) or arrange to have it run by others. If you show that PgJDBC's behaviour differs from how other drivers handle batches then it'll be worth thinking about adding an option to change the behaviour (and working on making it the default eventually).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值