Question

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);
Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top