Problem with android UPDATE

1

I'm having an issue giving update to a table in Android/SqLite :

I tried two ways I found:

String query = "UPDATE MY_TABLE SET VALUE1='VALUE1'... WHERE KEY_ID = KEY_ID"
SQLiteDatabase db = dbHelper.getWritableDatabase();
db.execSQL(query);

ContentValues values = new ContentValues();
values.put("VALUE1",VALUE1);
.
.
.
db.update("MY_TABLE",values,"KEY_ID="+KEY_ID,null);

Neither of the two forms is giving error, compiling normally but the values are not updated in the database. I have already debugged the application and the values are arriving correctly in the method, but it just does not update. When I recover the data again are without the modifications. Does anyone know what might be happening?

    
asked by anonymous 14.09.2016 / 21:48

1 answer

1

Try this:

db.update("MY_TABLE", values, "KEY_ID = ?", new String[]{String.valueOf(KEY_ID)});

According to documentation :

  

Can you include? in the WHERE clause, which will be replaced by the   values of the fourth parameter. The values will be linked as Strings.

    
14.09.2016 / 22:00