Android SqliteDatabase Command selectFromTable(SQLiteDatabase db, String table, String sample)

Here you can find the source of selectFromTable(SQLiteDatabase db, String table, String sample)

Description

select From Table

Declaration

public static ArrayList<String> selectFromTable(SQLiteDatabase db,
            String table, String sample) 

Method Source Code

//package com.java2s;

import android.database.Cursor;

import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;

public class Main {
    public final static String NESTLE_PRIMARY_KEY = "_id";
    public final static String NESTLE_COLUMN_1 = "date";
    public final static String NESTLE_COLUMN_2 = "first";
    public final static String NESTLE_COLUMN_3 = "last";
    public final static String NESTLE_COLUMN_4 = "difference";

    public static ArrayList<String> selectFromTable(SQLiteDatabase db,
            String table, String sample) {
        ArrayList<String> list = new ArrayList<String>();
        Cursor cursor = db.query(table, new String[] { NESTLE_COLUMN_1,
                NESTLE_COLUMN_2, NESTLE_COLUMN_3, NESTLE_COLUMN_4 },
                NESTLE_PRIMARY_KEY + " LIKE ?", new String[] { sample },
                null, null, null);/*w w  w . j  av  a2 s . com*/
        while (cursor.moveToNext()) {
            String s = null;
            StringBuffer buffer = new StringBuffer();
            for (String col : new String[] { NESTLE_COLUMN_2,
                    NESTLE_COLUMN_3, NESTLE_COLUMN_4 }) {
                s = cursor.getString(cursor.getColumnIndex(col));
                if (s != null && s.length() > 0)
                    buffer.append(s + ":");
                else
                    buffer.append("null:");
            }
            list.add(buffer.toString());
        }
        return list;
    }
}

Related

  1. executeSqlStatements(SQLiteDatabase db, String[] statements)
  2. executeSqlStatementsInTx(SQLiteDatabase db, String[] statements)
  3. getListOfDays(SQLiteDatabase db)
  4. insertIntoTable(SQLiteDatabase database, String table, String[] data)
  5. updateTable(SQLiteDatabase database, String table, String id, String[] newValues)
  6. getTaskCursor(SQLiteDatabase database, String name)
  7. SQLiteSanitize(String input)
  8. getFreeTourName(SQLiteDatabase db, String tourName)