Android Sqlite数据库没有得到更新

时间:2016-10-28 11:01:44

标签: android database sqlite

实现此代码后,db不会更新。请帮我找到解决方案。

public void updateBook(Book book) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, book.getBook()); // Contact Name
    values.put(KEY_PUBLISHER_ID, book.getPublisherId());
    values.put(KEY_SUBJECT, book.getSubject());
    values.put(KEY_PRICE, book.getPrice());
    values.put(KEY_CLASS, book.getClassFor());
    values.put(KEY_CODE, book.getCode());

    // updating row
    db.execSQL(Query);

    db.update(TABLE_BOOKS, values, KEY_ID + " = ?", new String[]{book.getId()});
    db.close();
}

也试过这个。

String Query = "UPDATE " + TABLE_BOOKS + " SET " + KEY_NAME + "='" + book.getBook() + "', " + KEY_PUBLISHER_ID
            + "='" + book.getPublisherId() + "', " + KEY_SUBJECT + "='" + book.getSubject() + "', " + KEY_PRICE + "='" + book.getPrice() + "', " + KEY_CLASS + "='" + book.getClassFor() + "', " + KEY_CODE + "='" + book.getCode()
            + "' WHERE " + KEY_ID + "=' " + book.getId() + "'";

    // updating row
    db.execSQL(Query);

0 个答案:

没有答案