get Integer List by database Query - Android Database

Android examples for Database:Cursor Get

Description

get Integer List by database Query

Demo Code


//package com.java2s;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.util.ArrayList;

public class Main {
    public static ArrayList<Integer> getIntegerListbyDBQuery(
            SQLiteDatabase db, String sql, String fieldName) {
        Cursor cursor = db.rawQuery(sql, null);
        int index = cursor.getColumnIndex(fieldName);
        ArrayList<Integer> retList = new ArrayList<Integer>();

        cursor.moveToFirst();/*  w  ww.j a  v a  2 s  .c om*/

        while (!cursor.isAfterLast()) {
            retList.add(cursor.getInt(index));
            cursor.moveToNext();
        }

        return retList;
    }
}

Related Tutorials