Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I try to switch ID for 2 rows in my database.

I get syntax error (code 1) on this line: ourDatabase.update(LIVE_TABLE, cv, whereClause, whereArgs);

Its strange becuase if this the row i look for wasnt exists than if(c.getCount() < 1) should give me return.

This the error code:

06-15 11:27:19.225: W/dalvikvm(10025): threadid=1: thread exiting with uncaught exception (group=0x40cc6930)
06-15 11:27:19.235: E/AndroidRuntime(10025): FATAL EXCEPTION: main
06-15 11:27:19.235: E/AndroidRuntime(10025): android.database.sqlite.SQLiteException: near "79": syntax error (code 1): , while compiling: UPDATE live_table SET 79=? WHERE _id= ?
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1563)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1514)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.example.workoutlog.DataBaseMain.updateMoveLive(DataBaseMain.java:2050)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.example.workoutlog.LiveWorkoutPage.moveDown(LiveWorkoutPage.java:1756)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.example.workoutlog.LiveWorkoutPage.whatclicked(LiveWorkoutPage.java:1600)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.example.workoutlog.LiveWorkoutPage.onClick(LiveWorkoutPage.java:583)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.view.View.performClick(View.java:4211)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.view.View$PerformClick.run(View.java:17362)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.os.Handler.handleCallback(Handler.java:725)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.os.Looper.loop(Looper.java:137)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at android.app.ActivityThread.main(ActivityThread.java:5226)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at java.lang.reflect.Method.invokeNative(Native Method)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at java.lang.reflect.Method.invoke(Method.java:511)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
06-15 11:27:19.235: E/AndroidRuntime(10025):    at dalvik.system.NativeStart.main(Native Method)
06-15 11:27:37.122: I/Process(10025): Sending signal. PID: 10025 SIG: 9

this is my code:

public void updateMoveLive(String where, String to)
    {

        String whereClause = COLUMN_ID + "= ? ";  
        String[] whereArgs = new String[]{where};

        ContentValues cv = new ContentValues();

        String[] columns = new String[]{COLUMN_ID, COLUMN_ROUTINE_LIVE, COLUMN_INT};

        Cursor c = ourDatabase.query(LIVE_TABLE, columns, whereClause , whereArgs, null, null, null);

        if(c.getCount() < 1)
            return;

        int i = c.getColumnIndex(COLUMN_ID);
        c.moveToFirst();
        String tempID = c.getString(i);

        cv.put(to, COLUMN_ID);

        ourDatabase.update(LIVE_TABLE, cv, whereClause, whereArgs);

                whereClause = COLUMN_ID + "= ? ";
                whereArgs = new String[]{tempID};

                cv = new ContentValues();

                cv.put(where, COLUMN_ID);

                ourDatabase.update(LIVE_TABLE, cv, whereClause, whereArgs);
    }
share|improve this question

1 Answer

up vote 1 down vote accepted

The error seems to be in this line:

cv.put(to, COLUMN_ID);

Should be

cv.put(COLUMN_ID, to)

as the ContentValue is, by default, ContentValue(KEY, VALUE)

EDIT: In fact, there is another incorrect use below, on

cv = new ContentValues();
cv.put(where, COLUMN_ID);

Try fix these two...

share|improve this answer
thanks, helped me :) – dasdasd 12 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.