Android更新查询错误

时间:2016-12-24 19:57:35

标签: android database sqlite android-sqlite sqliteopenhelper

我正在使用Sqlite在Android中实现更改密码。

我的查询是:

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();
}

它显示以下错误:

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

2 个答案:

答案 0 :(得分:0)

尝试更新记录

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

答案 1 :(得分:0)

尝试此更新记录 希望它能正常工作......

    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);
    }
}