How can I insert multiple rows into a database in a single transaction?

Anil Datt

//turn off the implicit commit

Connection.setAutoCommit(false);

//..your insert/update/delete goes here

Connection.Commit();

a new transaction is implicitly started.

Joe Sam Shirah comments: This question could be taken a couple of ways, so we included this answer as well:

Ryan Breidenbach adds:

JDBC 2.0 provides a set of methods for executing a batch of database commands. Specifically, the java.sql.Statement interface provides three methods: addBatch(), clearBatch() and executeBatch(). Their documentation is pretty straight forward.

The implementation of these methods is optional, so be sure that your driver supports these.

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact