[英]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.