How to count number of records in sqlite in Android

后端 未结 5 779
礼貌的吻别
礼貌的吻别 2020-12-16 13:05

I am working on android project. I used sqlite database for it. I have tables in database. I have created databasehelper class. i want to count number of records in particul

5条回答
  •  自闭症患者
    2020-12-16 13:48

    Using SELECT COUNT(*) FROM table_name query and, than count the size of Cursor..

    The method from Cursor to count size (number of rows in cursor) is,

    getCount()
    

    Returns the numbers of rows in the cursor.

    OR:

    From DatabaseUtils use method queryNumEntries(SQLiteDatabase db, String table)

    Like,

    long numberOfRows = DatabaseUtils.queryNumEntries(db, "table_name");

    which returns the number of rows in the table.

提交回复
热议问题