문제

I want to know how to use query method that have where clause with like property. basically what i want is to select all the columns WHERE C_NAME column is LIKE keyWord.

I've tried this, but it doesn't work:

cursor = db.query(TABLE, null, C_NAME, new String[] {"like '"+keyWord+"'"}, null, null, null);
도움이 되었습니까?

해결책

Look at the docs. They say:

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.

so try this:

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

Also see this answer as well to see some examples on how to use the selectionArgs (4th argument above). That is where keyWord would have to go.

다른 팁

this query work perfect for me

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top