1

我想知道如何使用具有属性where子句的查询方法。like基本上我想要的是选择所有列 WHERE C_NAME 列是 LIKE 关键字。

我试过这个,但它不起作用:

cursor = db.query(TABLE, null, C_NAME, new String[] {"like '"+keyWord+"'"}, null, null, null);
4

2 回答 2

1

查看文档。他们说:

selection   A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given table.

所以试试这个:

cursor = db.query(TABLE, C_NAME, new String[] {C_NAME + " like '" + keyWord + "'"}, null, null, null);

另请参阅此答案以查看有关如何使用selectionArgs(上面的第 4 个参数)的一些示例。那是keyWord必须去的地方。

于 2013-05-18T13:40:32.530 回答
0

这个查询非常适合我

光标 cursor = db.query(true, TABLE_NAME, new String[]{ COLUMNS }, ROW + " LIKE ?", new > String[] { "%" + name + "%" }, null, null, null, null );

于 2014-01-14T07:51:31.130 回答