4

I'm trying to use the following:

String dbquery = "Select * From stops where stopname LIKE '%?%' LIMIT 100";
String[] uinputarray = {uinput};
Cursor c = sDB.rawQuery(dbquery, uinputarray);

This consistently crashes.

Curiously, if I use the old test code of:

Cursor c = sDB.rawQuery("Select * From stops where stopname LIKE '%" + uinput + "%' LIMIT 100", null);

It works flawlessly.

I've been reading up on selectionArgs and I honestly can't see anything wrong with what I've done.

What am I doing wrong?

Thanks guys

1 Answer 1

7

You have to append the % to the selectionArgs itself:

selectionArgs = new String[] { searchString + "%" };

Cursor c = db.rawQuery("SELECT column FROM table WHERE column=?", selectionArgs);

Note: Accordingly % and _ in the searchString string still work as wildcards!

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

2 Comments

Thank you! So that's what I was doing wrong! It works great now. I'd give you an upvote but it requires more reputation. (sorry)
if answer is correct you should mark this as correct answer .

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.