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);
Saf
  • 227
  • 3
  • 11

2 Answers2

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.

Community
  • 1
  • 1
Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
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);