尝试删除行时出现SQLite异常

时间:2017-01-30 13:24:19

标签: android sqlite android-sqlite

我收到错误:

  

android.database.sqlite.SQLiteException:near“:BE”:语法错误   (代码1):,同时编译:DELETE FROM device WHERE   地址= 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;
}

我无法弄清楚出了什么问题。

3 个答案:

答案 0 :(得分:2)

使用带单引号的地址

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

答案 1 :(得分:1)

试试这个。

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

答案 2 :(得分:1)

使用它:

sqLiteDatabase.delete(" Table"," row =?",new String [] {String.valueOf(value)});