Java transactions. If you perform multiple operations on the database, each execution or step is a transaction. if the database operation is not executed at a certain step or the transaction fails due to an exception, some transactions will not be executed and the transaction will be rolled back, cancel previous operations .....
Note: To use transaction processing in Java, the database must support transactions first. If you use the MySQL transaction function, you must set the MySQL table type to InnoDB to support transactions. OtherwiseProgramBut cannot take effect in the database.
Use JDBC to process transactions in JavaBean
Public Int Delete ( Int Sid ){
DBC = New Databaseconnection ();
Connection Con = DBC. Get Connection ();
Try {
Con. setautocommit (false ); // Change the default commit Method for JDBC transactions
Dbc.exe cuteupdate ( "Delete from Xiao where id =" + Sid );
Dbc.exe cuteupdate ("Delete fromxiao_content where id =" + Sid );
Dbc.exe cuteupdate ("Delete fromxiao_affix where bylawid =" + Sid );
Con. Commit ();// Submit a JDBC transaction
Con. setautocommit (True); // Restore the default commit Method for JDBC transactions
DBC. Close ();
Return1;
}
Catch(Exception exc ){
Con. rollback (); // Roll back the JDBC transaction
Exc. printstacktrace ();
DBC. Close ();
Return-1;
}
}