select And Get Count from Database - Android Database

Android examples for Database:SQL Query

Description

select And Get Count from Database

Demo Code


//package com.book2s;

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

public class Main {
    public static int selectAndGetCount(Context context, String sql) {
        int result = 0;
        SQLiteDatabase db = context.openOrCreateDatabase("data.db",
                context.MODE_PRIVATE, null);
        Cursor cursor = db.rawQuery(sql, new String[] {});
        result = cursor.getCount();/*from   w  ww  .j av a2  s. co  m*/
        cursor.close();
        db.close();
        return result;
    }
}

Related Tutorials