在数组

时间:2015-12-14 21:55:33

标签: java android sql arrays database

我正在寻找一种将SQL查询的结果/输出存储到数组中的方法。我有一个运行查询的for循环,每次运行查询时我想将结果存储在数组/ arraylist中。我尝试使用游标,但我不能在游标中存储多个字符串。

这是for循环:

for (int i=1;i<code.length;i++) {
        Cursor cursor = myDataBase.query("codes", new String[]{"description"}, ("code = '" + code[i] + "'"), null, null, null, null);
        cursor.moveToFirst();
        String temp = cursor.getString(i);
        result.add(i, temp);
        cursor.close();

这似乎不起作用。

任何可能有用的建议或示例?

由于

1 个答案:

答案 0 :(得分:0)

假设code是一个id列表,并且表名称为codes,并且您想要检索所有代码的描述列表,请尝试这样做(使用{{1来自Apache commons):

StringUtils.join
相关问题