Android Update Query Error

80 views Asked by At

I am implementing change password in Android using Sqlite.

My query is:

try
{
    String update_query = "UPDATE " + TABLE_NAME + " SET " + PWD + "='" + temp_new_pwd + "' WHERE " + EMAIL + " = " + email;
    db.execSQL(update_query);
    Toast.makeText(getApplicationContext(), "Password Changed Successfully", Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
    Toast.makeText(getApplicationContext(), "Database Error", Toast.LENGTH_SHORT).show();
}

And it shows following error:

E/SQLiteLog: (1) near "@abc": syntax error
E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa29113f0
2

There are 2 answers

1
Bmbariah On BEST ANSWER

Try this for updating a record

ourDatabase = ourHelper.getWritableDatabase(); 
ContentValues values = new ContentValues(); 
values.put(PWD, new_pwd);
ourDatabase.update(DATABASE_TABLE, values, EMAIL + "=?", new String[]{email});
0
Neelesh On

Try this for updating a record hope it's working fine...

    public void updateQuantity(int id, int quantity) { if (quantity == 0)
        deleteItem(id);
    else {

        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(Constants.QUANTITY, quantity);
        values.put(Constants.DATE_NAME, String.valueOf(new DateTime()));
        int i = db.update(Constants.TABLE_NAME, values, Constants.KEY_ID + " = " + id, null);
    }
}