charon
08-15-2007, 05:49 AM
Hi,
A we know that we are using transaction when we do not want one statement to take effect unless another one completes. Either all of the statements are executed, or none of the statements is executed.
Normally I wil do as below:
<%
int result = 0;
int result2 = 0;
PreparedStatement updateSales = con.prepareStatement(
"UPDATE MYTABLEA SET STATUS = ? WHERE MYTABLEA_NUMBER = 'PM7610100'");
//updateSales.setInt(1, 50);
updateSales.setString(1, "N");
result = updateSales.executeUpdate();
PreparedStatement updateTotal = con.prepareStatement(
"UPDATE MYTABLEB SET STATUS= ? WHERE MYTABLEB_NUMBER = 'G761010'");
//updateTotal.setInt(1, 50);
updateTotal.setString(1, "Y");
result2 = updateTotal.executeUpdate();
if (result < 1){
con.rollback();
}
con.commit();
It will be difficult for me to use this approach of it involved more than two tables, Is there any better way of doing these?
pld advise.......
A we know that we are using transaction when we do not want one statement to take effect unless another one completes. Either all of the statements are executed, or none of the statements is executed.
Normally I wil do as below:
<%
int result = 0;
int result2 = 0;
PreparedStatement updateSales = con.prepareStatement(
"UPDATE MYTABLEA SET STATUS = ? WHERE MYTABLEA_NUMBER = 'PM7610100'");
//updateSales.setInt(1, 50);
updateSales.setString(1, "N");
result = updateSales.executeUpdate();
PreparedStatement updateTotal = con.prepareStatement(
"UPDATE MYTABLEB SET STATUS= ? WHERE MYTABLEB_NUMBER = 'G761010'");
//updateTotal.setInt(1, 50);
updateTotal.setString(1, "Y");
result2 = updateTotal.executeUpdate();
if (result < 1){
con.rollback();
}
con.commit();
It will be difficult for me to use this approach of it involved more than two tables, Is there any better way of doing these?
pld advise.......