SQLite in Android How to update a specific row SQLite in Android How to update a specific row java java

SQLite in Android How to update a specific row


First make a ContentValues object :

ContentValues cv = new ContentValues();cv.put("Field1","Bob"); //These Fields should be your String values of actual column namescv.put("Field2","19");cv.put("Field2","Male");

Then use the update method, it should work now:

myDB.update(TableName, cv, "_id = ?", new String[]{id});


Simple way:

String strSQL = "UPDATE myTable SET Column1 = someValue WHERE columnId = "+ someValue;myDataBase.execSQL(strSQL);


At first create a ContentValues object :

ContentValues cv = new ContentValues();cv.put("Field1","Bob");cv.put("Field2","19");

Then use the update method. Note, the third argument is the where clause. The "?" is a placeholder. It will be replaced with the fourth argument (id)

myDB.update(MY_TABLE_NAME, cv, "_id = ?", new String[]{id});

This is the cleanest solution to update a specific row.