public void update(View view) {

    SQLiteDatabase database = dbHelper.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put("price", 9.9);
    database.update(
        MyDatabaseHelper.TABLE_BOOK, values, "name = ?", new String[] {"Learn Android From 0"});
    database.close();
  }
 public void retrieve(View view) {
   SQLiteDatabase database = dbHelper.getReadableDatabase();
   Cursor cursor = database.query(MyDatabaseHelper.TABLE_BOOK, null, null, null, null, null, null);
   int count = 0;
   while (cursor.moveToNext()) {
     count++;
   }
   cursor.close();
   database.close();
   Toast.makeText(AtyUseDatabase.this, "total: " + count, Toast.LENGTH_SHORT).show();
 }
  public void add(View view) {
    SQLiteDatabase database = dbHelper.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put("author", "lovexiaov");
    values.put("price", 99.0);
    values.put("page", 399);
    values.put("name", "Learn Android From 0");
    database.insert(MyDatabaseHelper.TABLE_BOOK, null, values);
    Toast.makeText(AtyUseDatabase.this, "add data", Toast.LENGTH_SHORT).show();
    database.close();
  }
  public void useTransaction(View view) {
    SQLiteDatabase database = dbHelper.getReadableDatabase();
    database.beginTransaction();
    try {
      database.delete(MyDatabaseHelper.TABLE_BOOK, null, null);
      if (false) {
        throw new RuntimeException();
      }

      ContentValues values = new ContentValues();
      values.put(MyDatabaseHelper.BOOK_NAME, "WTF");
      values.put(MyDatabaseHelper.BOOK_AUTHOR, "lovexiaov");

      database.insert(MyDatabaseHelper.TABLE_BOOK, null, values);
      database.setTransactionSuccessful();
    } catch (RuntimeException e) {
      e.printStackTrace();
    } finally {
      database.endTransaction();
      database.close();
    }
  }
 public void delete(View view) {
   SQLiteDatabase database = dbHelper.getWritableDatabase();
   database.delete(MyDatabaseHelper.TABLE_BOOK, "name = ?", new String[] {"Learn Android From 0"});
   database.close();
 }