SQLite使用事务

关键代码

      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();
            }

  

posted @ 2017-04-21 11:42  rorshach  阅读(353)  评论(0编辑  收藏  举报