1

I am trying to update the contents of one row of DB here is my query:

public void updateAdhoc(String value1, String value2, String value3,String CONTACT_ID){

        int id = Integer.valueOf(CONTACT_ID);
        String update = "UPDATE Adhoc SET Name = " + "'"+value1+"'" +","+
                "DOB =  " + "'"+value2+"'" +","+
                "ImageData =  " + "'"+value3+"'" +","+
                "where " +adhocIdPrimary +"= " +id+";"; 

        mDb.execSQL(update);
    }

The code fails at the where clause. Following is my table creation string:

private static final String DATABASE_CREATE3 = "create table Adhoc (_id integer primary key autoincrement, "
            +"DOB text, " +
            "Name text not null, " +
            "ImageData text);";
    static final String DATABASE_TABLE3 = "Adhoc";

And following are my variables referencing the column names:

//Table Adhoc 
public static final String adhocIdPrimary = "_id";
public static final String adhocName = "Name";
public static final String adhocDob = "DOB";
public static final String adhocImageData = "ImageData";

The LogCat:

02-03 10:57:50.017: E/AndroidRuntime(9576): FATAL EXCEPTION: main
02-03 10:57:50.017: E/AndroidRuntime(9576): android.database.sqlite.SQLiteException: near "where": syntax error (code 1): , while compiling: UPDATE Adhoc SET Name = 'Ram Lal',DOB =  '2014-2-3 ',ImageData =  '/data/data/com.ex.xxx/files/xxx/adhoc1391405269898.jpg',where _id= 1;
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at com.exa.birthdayrem.DBAdapter.updateAdhoc(DBAdapter.java:421)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at com.ex.xxx.AdhocEdit$3.onClick(AdhocEdit.java:207)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.view.View.performClick(View.java:4091)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.view.View$PerformClick.run(View.java:17072)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.os.Handler.handleCallback(Handler.java:615)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.os.Looper.loop(Looper.java:153)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at android.app.ActivityThread.main(ActivityThread.java:5000)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at java.lang.reflect.Method.invokeNative(Native Method)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at java.lang.reflect.Method.invoke(Method.java:511)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
02-03 10:57:50.017: E/AndroidRuntime(9576):     at dalvik.system.NativeStart.main(Native Method)

3 Answers 3

5

You have an unwanted , comma before the where word. Just remove it and run again.

String update = "UPDATE Adhoc SET Name = " + "'"+value1+"'" +","+
                "DOB =  " + "'"+value2+"'" +","+
                "ImageData =  " + "'"+value3+"'" +","+   // remove this last comma
                "where " +adhocIdPrimary +"= " +id+";"; 
Sign up to request clarification or add additional context in comments.

Comments

2

Remove the , before WHERE and provide space after adhocIdPrimary

It will look like

String update = "UPDATE Adhoc SET Name = " + "'"+value1+"'" +","+
            "DOB =  " + "'"+value2+"'" +","+
            "ImageData =  " + "'"+value3+"'" +" "+
            "where " +adhocIdPrimary +" = " +id+";"; `

Comments

2

You need to remove comma that is before where and replace it with space:

String update = "UPDATE Adhoc SET Name = " + "'"+value1+"'" +","+
            "DOB =  " + "'"+value2+"'" +","+
            "ImageData =  " + "'"+value3+"'" +" "+
            "where " +adhocIdPrimary +"= " +id+";";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.