1. Introduction
When starting a transaction, only after all subsequent SQL are successful is considered successful, as long as there is one failure, all of them will fail, and rollback to before the transaction. For example ( Order settlement: check balance, check inventory, deduct balance, deduct inventory, create order, create logistics, this whole process should be a whole, any error in any link should be restored to the original state. )
//database.beginTransaction(); //启动事务
//database.setTransactionSuccessful(); //确认事务
//database.endTransaction(); //关闭事务
try{
database.beginTransaction(); //启动事务
//扣余额,扣库存,创建订单,创建物流---------
database.setTransactionSuccessful(); //确认事务
//确认success之后,尽量不要再有语句
}finally{
database.endTransaction(); //关闭事务
}