0

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?

1 Answer 1

1

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 + "%"};
Sign up to request clarification or add additional context in comments.

1 Comment

i wrote String whereClause = COL_ATTRIBUTI + " like ?"; String[] whereArgs = new String[] {"%" + s + "%"};

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.