addBatch()与autoCommit = true一起使用 [英] addBatch() used together with autoCommit = true

查看:130
本文介绍了addBatch()与autoCommit = true一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到这样的情况:

con.setAutoCommit(true);
Statement stmt = con.createStatement();
stmt.addBatch(query);//add all the queries
stmt.executeBatch();

每个查询是单独提交还是整个批次都会有一次提交?

Will each query commit separately or there will be a single commit for the entire batch?

注意:数据库是Oracle 11

Note : The database is Oracle 11

推荐答案

根据JDBC规范确切启用自动提交的批处理执行的行为是实现定义的。因此,它取决于数据库及其驱动程序,最好不要对确切的行为进行假设,并在使用批处理执行时禁用自动提交。

According to the JDBC specification the exact behavior of a batch execute with auto-commit enabled is implementation defined. So it depends on the database and its driver, and it is better to not make assumptions on the exact behavior and disable auto-commit when using batch executes.

JDBC 4.1,第14.1.1节说:


executeBatch的提交行为始终是实现定义的。

这只说明了错误条件,但暗示当批处理中的另一个语句抛出异常时,可能已经提交了单个语句。

This only says something about the behavior for error conditions, but the implication is that individual statements might already have been committed when another statement in the batch throws an exception.

这篇关于addBatch()与autoCommit = true一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆