sqlite db update

后端 未结 8 1680
暗喜
暗喜 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:27

    I know this a bit old, but in case anyone needed another way:

    public boolean updateNote(Note note) {
        SQLiteDatabase db = notesDbHelper.getWritableDatabase();
    
        ContentValues contentValues = new ContentValues();
        contentValues.put(NotesDbContract.NoteEntry._ID, note.getId());
        contentValues.put(NotesDbContract.NoteEntry.COLUMN_NAME_TITLE, note.getTitle());
        contentValues.put(NotesDbContract.NoteEntry.COLUMN_NAME_DSECRIPTION, note.getDescription());
    
        int result = db.update(NotesDbContract.NoteEntry.TABLE_NAME,
                contentValues,
                NotesDbContract.NoteEntry._ID + "=?", new String[]{String.valueOf(note.getId())}
        );
        db.close();
    
        return result > 0;
    }
    

提交回复
热议问题