Change a value in a column in sqlite

后端 未结 2 2023
孤城傲影
孤城傲影 2021-02-19 09:52

I need to update a value in a column from a certain table. I tried this :

 public void updateOneColumn(String TABLE_NAME, String Column, String rowId, String Col         


        
2条回答
  •  灰色年华
    2021-02-19 10:39

    Easy solution:

    String sql = "UPDATE "+TABLE_NAME +" SET " + ColumnName+ " = '"+newValue+"' WHERE "+Column+ " = "+rowId;
    

    Better solution:

    ContentValues cv = new ContentValues();
    cv.put(ColumnName, newValue);
    db.update(TABLE_NAME, cv, Column + "= ?", new String[] {rowId});
    

提交回复
热议问题