关键代码
SQLiteDatabase db = myDataHelper.getWritableDatabase(); // 开启事务 db.beginTransaction(); try{ db.delete("book", null, null); if(true){ throw new NullPointerException(); } db.execSQL("INSERT INTO book(name, author, pages, price) VALUES(?,?,?,?)", new String[]{"qihuanzhilv2", "daxiao", "500", "10.50"}); }catch (Exception e){ e.printStackTrace(); }finally { //结束事务 db.endTransaction(); }