这是我想要运行的SQL查询:
Cursor cursor = sqLiteDatabase.rawQuery("UPDATE collection SET datetime=\"" + (newDate) + "\"" + " WHERE region =" + region, null);
但是我应该用光标来调用此查询来更新我的数据库?
答案 0 :(得分:1)
请改用sqLiteDatabase.execSQL()
。 rawQuery
与SELECT
操作
String updateQuery = "UPDATE collection SET datetime= '" + (newDate) + "' WHERE region = '" + region;
sqLiteDatabase.execSQL(updateQuery);
答案 1 :(得分:1)
用于更新数据库:
SQLiteDatabase sqLiteDatabase= this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("datetime", newDate);
// updating row
// if region is string! otherwise convert it into string
sqLiteDatabase.update(collection, values, "region" + " = ?",
new String[] { region });