how can i use an Array of strings to query an sqlite database? i keep getting the exception “SQliteException: bind or column index out of range”.
String[] names = new String[values.size()]; // values is an Arraylist
String[] condition = values.toArray(names);
Cursor row = db.query(true,DATABASE_TABLE, resultColumns, NAME +"=" + "?", condition, null, null, null,null);
please any help will be greatly appreciated as usual. Thanks
P.S values, which is the Arraylist is being poplulated through a loop so i can’t have a defined size. thats why i can’t use the get() method and seperate the elements in it by commas’ which would have been easier.
Your query’s where clause is
where name = ?. This expects the passed-in array to be of size 1. Judging by its name (names), I’m guessing its not. You need to rethink what you want your SQL query to be (maybewhere name in ...).E.g.:
You need to implement
String convertToCommaDelimitedString(Collection c);