Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

connection.setAutoCommit(false) in batch updates

843859Mar 13 2008 — edited Mar 14 2008
Hy, I have somes doubts with batch updates. Here they goe. I have the next code:

Class.forName("com.mysql.jdbc.Driver");
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost/clients", "root", "");
connection.setAutoCommit(false);
Statement sentence=connection.createStatement();
sentence.addBatch("INSERT INTO dataclients dni VALUES('45464564' );
sentence.addBatch("INSERT INTO dataclients dni VALUES('456456');
sentence.executeBatch();

1.This line " connection.setAutoCommit(false)" means that all the sentences sent by the executeBatch() will not be permanent and so then I will have to call "connection.commit" after "sentence.executeBatch()" to make them permanent?
2.What happens if I dont use "connection.setAutoCommit(false)"? The batch is not executed like a batch? The sentences of the batch are sent one by and not in group?

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 11 2008
Added on Mar 13 2008
6 comments
1,132 views