I am developing an android app, in which I need update a column in a table based on the a certain where clause.Here is the code below,
public void updatethekeyofweeklycolumn(String profilename, String keystemp)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Profile_keysofweekly, keystemp);
db.update(TABLE_PROFILE_SETTINGS_FOR_WEEKLY, values,Profile_Name_for_weekly +" = "+profilename, null);
}
The above code is working fine with where clause as null, but its throwing a force close with the whereclause is set. Is my Query wrong?
You need to escape profilename. So you either add the single ' character:
db.update(TABLE_PROFILE_SETTINGS_FOR_WEEKLY, values,Profile_Name_for_weekly +" = '"+ profilename + "'", null);
Or, the option I would follow:
db.update(TABLE_PROFILE_SETTINGS_FOR_WEEKLY, values,Profile_Name_for_weekly +" = ?", new String[] {profilename});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With