Java 如何使用游标从sqlite表中获取整个列?

Java 如何使用游标从sqlite表中获取整个列?,java,android,sql,sqlite,Java,Android,Sql,Sqlite,我有一个称为集合的字符串数组 String[] Collections; 我的db表中保存了整数值。我想从名为specific_collections的数据库列中获取整数值 String[] Collections; 并将其设置为整数数组 String[] Collections; 所以,我想这样设置: String[] Collections = 0; Integer[] SpecificCollections = getColumnValuesFromSpecificCollectio

我有一个称为集合的字符串数组

String[] Collections;
我的db表中保存了整数值。我想从名为specific_collections的数据库列中获取整数值

String[] Collections;
并将其设置为整数数组

String[] Collections;
所以,我想这样设置:

String[] Collections = 0;
Integer[] SpecificCollections = getColumnValuesFromSpecificCollectionsColumn(); 
将它们设置为整数数组后,我想解析整数数组并将每个int值保存到字符串数组中,该字符串数组的形式如下:

Collections = new String[]{Collection.SpecificCollections.fromInt(SpecificCollections[i]).getString()};
其中,Specific Collections是db中的整数数组

编辑:这是我到目前为止得到的,但它只是用一个int填充列表

ArrayList<Integer> regionList= new ArrayList<Integer>();
 Cursor cursorTwo = sqLiteDatabase.rawQuery("SELECT DISTINCT region FROM collection", null);
            if (cursorTwo != null && cursorTwo.getCount() != 0) {
                cursorTwo.moveToFirst();  
                while (!cursorTwo.isAfterLast()) {
                    regionList.add(cursorTwo.getInt(0));
                    cursorTwo.moveToNext();
                }
            }
            for (Integer inte : regionList){
                regions = new String[]{Collection.Regions.fromInt(inte).getString()};
            }
ArrayList regionList=新建ArrayList();
Cursor cursorTwo=sqLiteDatabase.rawQuery(“从集合中选择不同的区域”,null);
if(cursorTwo!=null&&cursorTwo.getCount()!=0){
游标两个。移动到第一个();
而(!cursorTwo.isAfterLast()){
regionList.add(cursorTwo.getInt(0));
cursorTwo.moveToNext();
}
}
for(整数inte:regionList){
regions=新字符串[]{Collection.regions.fromInt(inte.getString()};
}

下面是迭代数组列表并在fromInt()方法中传递不同整数的正确方法吗

在SQLiteDatabase.query()方法中,将selection和selectionArgs参数设置为null。例如,请参见以下代码:

String[] projection = { COLUMN_NAME }
Cursor cursor = mSQLiteDb.query(TABLE_NAME, projection, null, null, null, null, null);

ArrayList<Integer> values = new ArrayList<Integer>();
if (cursor != null && cursor.getCount() != 0) {
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {

        values.add(cursor.getInt(cursor.getColumnIndex(COLUMN_NAME)));

        cursor.moveToNext();
    }
}
String[]projection={COLUMN\u NAME}
Cursor Cursor=mSQLiteDb.query(表名,投影,null,null,null,null);
ArrayList值=新的ArrayList();
if(cursor!=null&&cursor.getCount()!=0){
cursor.moveToFirst();
而(!cursor.isAfterLast()){
add(cursor.getInt(cursor.getColumnIndex(COLUMN_NAME));
cursor.moveToNext();
}
}

您能告诉我如何使用游标进行查询吗?我尝试了一些解决方案,但没有一个奏效。仅显示最后一个值。我试过这个解决方案,但不起作用:嗯,你能解释一下它怎么不起作用吗?有什么错误信息吗?我更新了我的答案,请尝试代码。什么是setNumValue?在这种情况下,myObject应该是什么?您可以忽略myObject,我添加它是为了向您展示您可以在任何位置存储列的返回值。我再次更新了代码,并用整数数组列表替换了myObject。别忘了关闭游标。