get Table row Count - Android Database

Android examples for Database:Table Row Query

Description

get Table row Count

Demo Code


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

public class Main {
    public static int getItemsCount(SQLiteDatabase database,
            String tableName) {/*from  w ww  .j  a  v a2 s. c  o m*/
        String[] columns = { "COUNT(*)" };
        Cursor resultCursor = database.query(tableName, columns, null,
                null, null, null, null);
        resultCursor.moveToFirst();
        return resultCursor.getInt(0);
    }

    public static Cursor query(SQLiteDatabase database, String tableName,
            String[] columns, String selection, String[] selectionArgs,
            String groupBy, String having, String orderBy, String limit) {
        return database.query(tableName, columns, selection, selectionArgs,
                groupBy, having, orderBy, limit);
    }
}

Related Tutorials