简体   繁体   English

如何更新我的sqlite数据库中的值?

[英]How can I update the values in my sqlite database?

Here's the sql query I want to run: 这是我要运行的SQL查询:

 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. 请改用sqLiteDatabase.execSQL() rawQuery is used with SELECT operation rawQuerySELECT操作一起使用

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 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM