Get data from Columns - Android Database

Android examples for Database:Table Column

Description

Get data from Columns

Demo Code


//package com.java2s;
import java.util.ArrayList;
import java.util.Arrays;

import java.util.List;

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

import android.util.Log;

public class Main {
    public static List<String> GetColumns(SQLiteDatabase db,
            String tableName) {//from w w  w  . jav  a2s  . co  m
        List<String> ar = null;
        Cursor c = null;
        try {
            c = db.rawQuery("select * from " + tableName + " limit 1", null);
            if (c != null) {
                ar = new ArrayList<String>(
                        Arrays.asList(c.getColumnNames()));
            }
        } catch (Exception e) {
            Log.v(tableName, e.getMessage(), e);
            e.printStackTrace();
        } finally {
            if (c != null)
                c.close();
        }
        return ar;
    }
}

Related Tutorials