Skip to content

Batch Transaction

Ashish Shukla edited this page Aug 31, 2018 · 1 revision

To initiate the multiple insert transactions at once, follow below steps-

create jdbc statement object

   Statement stmt = conn.createStatement();

use addBatch method to add insert query statement

   stmt.addBatch(query1);
   stmt.addBatch(query2);
   stmt.addBatch(query3);
   stmt.addBatch(query4);
   stmt.addBatch(query5);
   stmt.addBatch(query6);
   stmt.addBatch(query7);
   stmt.addBatch(query8);

And finally use executeBatch method to run all the queries

 int[] output = stmt.executeBatch();

output array contains the status of each query in JDBC standard. if index value equals -3, it means Execution was failed for the query at that particular index.

if index value equals 1, it means Execution was successfully completed.

Note: You can not rollback the transaction once it started.