sqliteDatabase db = ....;
db.beginTransaction();//开始事务
try {
db.execsql("insert into person(name,age) values(?,?)",new Object[]{"传智播客",4});
db.execsql("update person set name=? where personid=?",new Object[]{"传智",1});
();//调用此方法会在执行到endTransaction() 时提交当前事务,如果不调用此方法会回滚事务
db.setTransactionSuccessful
} finally { db.endTransaction();//由事务的标志决定是提交事务,还是回滚事务 } db.close();
原文链接:https://www.f2er.com/sqlite/202380.html