fetch List of String from SQLiteDatabase by table name - Android Database

Android examples for Database:Table Row Query

Description

fetch List of String from SQLiteDatabase by table name

Demo Code


//package com.java2s;

import java.util.ArrayList;
import java.util.List;

import android.database.Cursor;

import android.database.sqlite.SQLiteDatabase;

public class Main {
    private final static String TABLE_NAME = "all_areas";

    public static List<String> fetchResort(SQLiteDatabase sqliteDatabase) {
        List<String> countries = new ArrayList<String>();
        if (sqliteDatabase != null) {
            Cursor cursor = null;
            cursor = sqliteDatabase.query(true, TABLE_NAME,
                    new String[] { "resort_country" }, null, null, null,
                    null, null, null);// w  ww  . ja  v  a 2s .c  o m
            if (cursor != null) {
                while (cursor.moveToNext()) {
                    countries.add(cursor.getString(0));
                }
            }
        }
        return countries;
    }
}

Related Tutorials