Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在数组中存储SQL查询输出_Java_Android_Sql_Arrays_Database - Fatal编程技术网

Java 在数组中存储SQL查询输出

Java 在数组中存储SQL查询输出,java,android,sql,arrays,database,Java,Android,Sql,Arrays,Database,我正在寻找一种将SQL查询的结果/输出存储到数组中的方法。我有一个运行查询的for循环,每次运行查询时,我都希望将结果存储在array/arraylist中。我尝试使用游标,但无法在游标中存储多个字符串 下面是for循环: for (int i=1;i<code.length;i++) { Cursor cursor = myDataBase.query("codes", new String[]{"description"}, ("code = '" + code[i]

我正在寻找一种将SQL查询的结果/输出存储到数组中的方法。我有一个运行查询的for循环,每次运行查询时,我都希望将结果存储在array/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();

for(int i=1;i假设
code
是一个ID列表,表名为
code
,并且您希望检索所有代码的描述列表,您应该这样做(使用
StringUtils.join
从):


假设
code
是一个ID列表,表名命名为
code
,并且您希望检索所有代码的描述列表,您应该这样做(使用
StringUtils.join
from):


为什么需要在数组中存储
光标的内容
?假设
code
是一个ID列表,并且表名为
code
,您希望检索所有代码的描述列表?为什么需要在数组中存储
光标的内容
?假设
code>
是ID列表,表名为
codes
,是否要检索所有代码的描述列表?
String codes = StringUtils.join(code,",");  
Cursor  cursor = myDataBase.rawQuery("select description from codes where code in (?)",new String[]{codes});
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()){
    result.add(cursor.getString(1));
}
cursor.close();