Update Query not working in Android Sqlite

android, android-sqlite, sqlite

Solution

Use `execSQL()` for such SQL and not `rawQuery()`.

`rawQuery()` just compiles the SQL but does not run it. You'd need to call one of the `move...()` methods on the returned `Cursor` to execute a step of the compiled SQL program.

`execSQL()` both compiles and runs the SQL program.

There's also possibly a syntax problem with your literals - use parameters i.e. `?` placeholders in SQL and `String[]` bind arguments to be safe.

Problem

My Java code Update Data base Table ``` String qq="UPDATE ChallanItems SET Recieve ="+str+" WHERE ItemNo = "+code; Log.d("Qry", qq); myDbHelper.updatequery(qq); ``` updatequery method ``` public void updatequery(String qry) { Cursor c = myDataBase.rawQuery(qry, null); Log.d("Up", ""+c.getCount()); } ``` When i updated Data base the count return 0 and table not updated I am using this Also but not work ``` String qq="UPDATE ChallanItems SET Recieve ="+str+" WHERE ItemNo = "+"'"+code+"'"; ``` Please Help Me how i can fix this problem Thanks In Advance

Original source