开发者

Batch Stored procedures insertion in database with Callable statement

开发者 https://www.devze.com 2022-12-14 21:38 出处:网络
We have 4 st开发者_C百科ored procedures which we are using to insert the entries in database, These 4 are interdependent, If any of this fails Whole operation has to be rolled back, only if everything

We have 4 st开发者_C百科ored procedures which we are using to insert the entries in database, These 4 are interdependent, If any of this fails Whole operation has to be rolled back, only if everything goes well I want to commit the transaction. How do I achieve that.

Thanks, Rohit.


You need to use JDBC's transaction support, which is described in the JDBC Tutorial here.

Pseudo-code:

Connection conn = ...
conn.setAutoCommit(false);
try {
   doAction1(connection);
   doAction2(connection);
   doAction3(connection);
   doAction4(connection);

   connection.commit();
} catch (Exception ex) {
   connection.rollback();
}

Plus all the usual closing of connections, statements, etc.

The link describes the specifics.

0

精彩评论

暂无评论...
验证码 换一张
取 消