I am updating Status_msg
column using Update
query in Sqlite Database by value 1 to 0. The Syntax error occurred when compiling the application.
The Log cat
02-20 09:45:36.145 19350-19350/com.smsfilter E/SQLiteLog: (1) near "1": syntax error
02-20 09:45:36.145 19350-19350/com.smsfilter D/AndroidRuntime: Shutting down VM
02-20 09:45:36.145 19350-19350/com.smsfilter W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40a71930)
02-20 09:45:36.195 19350-19350/com.smsfilter E/AndroidRuntime: FATAL EXCEPTION: main
android.database.sqlite.SQLiteException: near "1": syntax error (code 1): , while compiling: UPDATE sms_tbl SET 1 = 0 where 1 = 1
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnecti on.java:882)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
at com.smsfilter.DB_Message.setStatus(DB_Message.java:106)
at com.smsfilter.SpamActivity$datalist$1.onCheckedChanged(SpamActivity.java:208)
at android.widget.CompoundButton.setChecked(CompoundButton.java:126)
at android.widget.CompoundButton.toggle(CompoundButton.java:87)
at android.widget.CompoundButton.performClick(CompoundButton.java:99)
at android.view.View$PerformClick.run(View.java:17355)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
The Update function is given below
public int setStatus(){
SQLiteDatabase sqldb = this.getWritableDatabase();
String status_change_query = "UPDATE " + DB_Table1 + " SET " + Status_Msg + " = 0 where " + Status_Msg + " = 1";
Cursor cursor = sqldb.rawQuery(status_change_query,null);
cursor.close();
System.out.println(""+ Status_Msg);
sqldb.close();
return Status_Msg;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…