SQLite 中的 Where 子句在 android 中不起作用:(
问题描述:
当我尝试在 SQLite 中查询某些数据时遇到一个烦人的错误.
I'm getting an annoying error when trying to query some data in SQLite.
这是我的代码:
Cursor cursor= db.query(TABLE_IMAGES, new String[]{"_id"}, "name" +" = "+compareToThis, null, null, null, null);
我只是将光标作为字符串返回.
I'm just returning the cursor as a string.
错误是说:
没有这样的列:compareToThis: while compiling ..... the statement
no such column: compareToThis: while compiling.....the statement
我的问题是:当它只是一个值时,为什么 SQLite 将 compareToThis 属性设置为列?
My question is: why is SQLite setting the compareToThis attribute as a column when it's just a value?
我该如何解决这个问题?
How can I fix this?
提前致谢.
答
Cursor cursor= db.query(TABLE_IMAGES, new String[]{"_id"}, "name" +" = ?", new String[]{compareToThis}, null, null, null);
选择必须包含参数占位符,下一个参数应该是参数数组.
The selection must include placeholder for parameter, and the next argument should be the array of parameters.