Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a situation like this :

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?

Note : The database is Oracle 11

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
193 views
Welcome To Ask or Share your Answers For Others

1 Answer

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, section 14.1.1 says:

The commit behavior of executeBatch is always implementation-defined when an error occurs and auto-commit is true.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...