Skip to content Skip to sidebar Skip to footer

Android - Sqlite In Clause Using Values From Array

I want to execute a sqlite query: select * from table_name where id in (23,343,33,55,43); The values in the in clause need to be taken from an array of strings: String values[] =

Solution 1:

I believe a simple toString() will mostly do the trick:

String values[] = {"23","343","33","55","43"};
String inClause = values.toString();

//at this point inClause will look like "[23,343,33,55,43]"
//replace the brackets with parentheses
inClause = inClause.replace("[","(");
inClause = inClause.replace("]",")");

//now inClause will look like  "(23,343,33,55,43)" so use it to construct your SELECT
String select = "select * from table_name where id in " + inClause;

Post a Comment for "Android - Sqlite In Clause Using Values From Array"