sqlite db update

后端 未结 8 1675
暗喜
暗喜 2020-12-11 09:14

Is there an easy way to update a table in sqlite in android? (like a single line in built method) ? I have a table with few columns and primary is one column. I want to sear

8条回答
  •  春和景丽
    2020-12-11 09:15

    To use with predefined update method from android, use it as below:

    ContentValues args = new ContentValues();
    args.put("col_name", "new value");
    
    db.update("table_name", args, String.format("%s = ?", "primary_column"),
               new String[]{"primary_id"});
    

    Or to run as a single line, go with this (not recommended):

    db.execSQL("UPDATE table_name SET col_name='new_value' WHERE
               primary_column='primary_id'");
    

提交回复
热议问题