Here's the sql query I want to run:
Cursor cursor = sqLiteDatabase.rawQuery("UPDATE collection SET datetime=\"" + (newDate) + "\"" + " WHERE region =" + region, null);
But what am I supposed to do with the cursor to call this query to update my database?
Use sqLiteDatabase.execSQL()
instead. rawQuery
is used with SELECT
operation
String updateQuery = "UPDATE collection SET datetime= '" + (newDate) + "' WHERE region = '" + region;
sqLiteDatabase.execSQL(updateQuery);
for updating database:
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 });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.