get data from Database table by sql and table name - Android Database

Android examples for Database:SQL Query

Description

get data from Database table by sql and table name

Demo Code


//package com.book2s;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Main {
    public static String[] getData(SQLiteDatabase db, String sql,
            String TABLE_NAME) {/*from  w ww . j  a  v a2  s. c om*/

        Cursor cursor = db.rawQuery(sql, null);
        int dataNum = cursor.getCount();
        String[] strData = new String[dataNum];
        for (int i = 0; i < dataNum; i++) {
            strData[i] = cursor.getString(0);
            cursor.moveToNext();
        }
        return strData;
    }
}

Related Tutorials