SQLite exception while trying to delete row

梦想与她 提交于 2019-12-13 11:13:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!