2017-01-30 80 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(值)});