2017-01-30 77 views
-2

我收到提示:SQLite的例外尝试删除行

android.database.sqlite.SQLiteException: near ":BE": syntax error (code 1): , while compiling: DELETE FROM device WHERE address=C4:BE:84:18:D5:A5

,同时试图从SQLite数据库中删除的行。

public int removeDevice(String address) { 
    open(); 
    int removedId = database.delete(MySQLiteHelper.TABLE_DEVICE 
       , MySQLiteHelper.KEY_ADDRESS + "=" + address, null); 
    close(); 

    return removedId; 
} 

我找不出什么问题。

+1

是'address'一个字符串?需要引用字符串 –

+0

@VladMatvienko是的,确实如此:这是一个MAC地址。 –

回答

1

试试这个。

int removedId = database.delete(MySQLiteHelper.TABLE_DEVICE 
      , MySQLiteHelper.KEY_ADDRESS + "= ?",new String[] {address}); 
2

使用地址与单引号

DELETE FROM device WHERE address='C4:BE:84:18:D5:A5' 
+0

来自Rahul Giradkar's和Divyesh的回答 – Selvin

1

使用这样的:

sqLiteDatabase.delete( “表”, “?行=”,新的String [] {将String.valueOf(值)});