无法从sqlite数据库android删除行

时间:2013-09-02 13:20:57

标签: java android database sqlite handler

我试图从我的sqlite数据库中删除一行。

我的处理程序类:

// Deleting single contact
    public void deleteContact(WhiteList contact) {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
                new String[] { String.valueOf(contact.getID()) });
        db.close();
    }

 // Deleting single contact
    public void deleteTitle(int name) 
    {
        try {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(TABLE_CONTACTS, KEY_ID + "=" + name, null);
        Log.d("workingasdfasdfasdf", "deleted: " + name);
        db.close();
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

我试过了两个,但没有他们正在工作。

我调用代码:db.deleteTitle(1); //delete record with the ID of "1" onClick of a按钮

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

尝试使用单引号关闭名称:

db.delete(TABLE_CONTACTS, KEY_ID + "='" + name + "'", null);