Reputation: 517
I would make a query using like
, using the % and a dynamic string, but i can't do it correctly.
I have a:
public Cursor query(String s)
{
String whereClause=COL_ATTRIBUTI + " like '%?%'";
String[] whereArgs=new String[] {s};
return getWritableDatabase().query(TABELLA_RICETTE,null,whereClause,whereArgs,null,null,null);
}
COL_ATTRIBUTI is the name of a column and TABELLA_RICETTE the name of the table.
I would like to obtain all the thing that have s
somewhere, so i use the %. but my app crash. What is the correct syntax?
Upvotes: 0
Views: 159
Reputation: 38585
I think you need to put the %
wildcards in the argument if you are using the ?
placeholders:
String whereClause = COL_ATTRIBUTI + " like '?'";
String[] whereArgs = new String[] {"%" + s + "%"};
Upvotes: 1