[英]Android - sqlite in clause using values from array
我想执行一个sqlite查询:
select * from table_name where id in (23,343,33,55,43);
in
子句中的值需要从字符串数组中获取:
String values[] = {"23","343","33","55","43"}
我怎样才能做到这一点?
我相信一个简单的toString()
可以解决大部分问题:
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.