fetch Cursor By table name from SQLiteDatabase - Android Database

Android examples for Database:Table Row Query

Description

fetch Cursor By table name from SQLiteDatabase

Demo Code


//package com.java2s;

import android.database.Cursor;

import android.database.sqlite.SQLiteDatabase;

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

    public static Cursor fetchResortByCountry(
            SQLiteDatabase sqliteDatabase, String country) {
        Cursor cursor = null;/*from www . j a  v  a2  s  . c  o  m*/
        if (sqliteDatabase != null && country != null) {
            cursor = sqliteDatabase.query(true, TABLE_NAME, new String[] {
                    "id", "resort_name", "resort_region", "resort_id" },
                    "resort_country='" + country + "'", null, null, null,
                    null, null);
            if (cursor != null) {
                cursor.moveToFirst();
            }
        }
        return cursor;
    }
}

Related Tutorials