xyz xyz - 1 month ago 8
Android Question

SQLiteException: unrecognized token in UPDATE statement

This is my update query,

ContentValues value = new ContentValues();
value.put(DBhelper.Amount, txtBudget.getText().toString());



db = helper.getWritableDatabase();

db.update(DBhelper.TABLE1, value," "+DBhelper.Description+"='"+value_in_tv,null);
db.close();

fetchData2();
Toast.makeText(this, "Update Successfully", Toast.LENGTH_LONG).show();
clearfield();


when click the button to update,it's giving fatal exception error.

value_in_tv
this is the value I got from another class

Bundle data_from_list= getIntent().getExtras();
value_in_tv= data_from_list.getString("passed data key");
txr.setText(value_in_tv);


Error:

10-18 20:45:57.812 18632-18632/com.example.username.weddingplanning
E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.database.sqlite.SQLiteException: unrecognized token: "'suba" (code 1): , while compiling: UPDATE Category SET amount=?
WHERE description='suba
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:686)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1669)
at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1620)
at com.example.username.weddingplanning.addbudget.checkIfRowPresent(addbudget.java:134)
at com.example.username.weddingplanning.addbudget.onClick(addbudget.java:114)
at android.view.View.performClick(View.java:4439)
at android.view.View$PerformClick.run(View.java:18398)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)

Answer

You forgot the closing ' in the where clause:

 db.update(DBhelper.TABLE1, value," "+DBhelper.Description+"='"+value_in_tv + "'",null)
Comments