Skip to Content
0
Former Member
Sep 08, 2009 at 07:42 PM

Commit / RollBack

55 Views

Hi,

I want to execute 2 or more database operation in one transcation with commit/rollback mechanism.

Below is my code,

How can i make it has commit /rollback (in one transaction).

Thanks.

InitialContext ctx = new InitialContext();

DataSource ds = (DataSource) ctx.lookup("jdbc/SAPXXXDB");

Connection con1 = ds.getConnection();

Connection con2 = ds.getConnection();

PreparedStatement pstm1 =con1.prepareStatement("insert into ZTABLE1(...)Values(...)";

PreparedStatement pstm2 =con2.prepareStatement("insert into ZTABLE2(...)Values(...)";

pstm1.executeUpdate();

pstm2.executeUpdate();

con1.close();

con2.close();