本文介绍了Android-使用数组中的值的sqlite in子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要执行一个sqlite查询:
I want to execute a sqlite query:
select * from table_name where id in (23,343,33,55,43);
in
子句中的值需要从字符串数组中获取:
The values in the in
clause need to be taken from an array of strings:
String values[] = {"23","343","33","55","43"}
我该如何实现?
推荐答案
我相信一个简单的toString()
就能解决问题:
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;
这篇关于Android-使用数组中的值的sqlite in子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!