问题
I'm getting error:
android.database.sqlite.SQLiteException: near ":BE": syntax error (code 1): , while compiling: DELETE FROM device WHERE address=C4:BE:84:18:D5:A5
while trying to remove row from sqlite database.
public int removeDevice(String address) {
open();
int removedId = database.delete(MySQLiteHelper.TABLE_DEVICE
, MySQLiteHelper.KEY_ADDRESS + "=" + address, null);
close();
return removedId;
}
I can't figure out what's wrong.
回答1:
Try this.
int removedId = database.delete(MySQLiteHelper.TABLE_DEVICE
, MySQLiteHelper.KEY_ADDRESS + "= ?",new String[] {address});
回答2:
use address with single quotes
DELETE FROM device WHERE address='C4:BE:84:18:D5:A5'
回答3:
use this :
sqLiteDatabase.delete("Table", "row= ?", new String[]{String.valueOf(value)});
来源:https://stackoverflow.com/questions/41937027/sqlite-exception-while-trying-to-delete-row