Problem with android UPDATE

Asked

Viewed 70 times

1

I got a problem when it comes to giving update in a table on Android/SqLite:

I tried both 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 ways is giving error, compile normally but the values are not updated in the database. I’ve debugged the application and the values are coming correctly in the method, but it just doesn’t update. When I recover the data again are without the modifications. Does anyone know what might be occurring?

  • in the first form, tries to make: query = "commit;"; db.execSQL(query);

  • java.lang.Illegalstateexception: Cannot perform this Operation because there is no Current transaction.

  • returned this error there when I tried to commit

1 answer

1

Try it this way:

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

According to the documentation:

You can include ? in the WHERE clause, which will be replaced by values of the fourth parameter. Values will be linked as Strings.

  • Yes I can include and fetch normally in the bank! I tried that way there and it still hasn’t been!

  • You close the connection? db.close () ?

  • See what value the update returns. If it is 1 is because the line was affected

  • well, it worked... I wasn’t really closing the connection, but I don’t think it makes much sense that it’s not working because of it! But even so thank you very much, solved the problem, then when I have more time I will research about it! Really worth!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.