Android 更新 SQLite table 条目

Android update SQLite table entry

我在 may 应用程序中有一个本地 SQLite 数据库。我这样创建并打开数据库:

CookieClickerBase = getBaseContext().openOrCreateDatabase(CookieBase, MODE_PRIVATE, null);
CookieClickerBase.execSQL("CREATE TABLE IF NOT EXISTS cookiedata(what TEXT, data LONG)");

我在 table link 中插入一些薄的:

CookieClickerBase.execSQL("INSERT INTO cookiedata VALUES ('Image','3')");

但现在我不会将 table 条目中的数据从 3 更改为 9,其中 what = Image。 我该怎么做?

谢谢!

您可以将 UPDATE 语句与 execSQL():

一起使用
CookieClickerBase.execSQL("UPDATE cookiedata SET data = 9 WHERE what ='Image'");

或使用推荐的方法 update()ContentValues:

ContentValues cv = new ContentValues();
cv.put("data", "9");
int rows = CookieClickerBase.update("cookiedata", cv, "what = ?", new String[] {"Image"});

变量rows将包含更新的行数。