1

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);

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The answer from the other question is exactly what i was looking for, thanks.
0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.