How to count number of records in sqlite in Android

后端 未结 5 777
礼貌的吻别
礼貌的吻别 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:59

    In Kotlin

    fun getFruitTableCount(): Int {
            val db = readableDatabase
            val numRows = DatabaseUtils.longForQuery(db, "SELECT COUNT(*) FROM " + DBContract.FruitEntry.TABLE_NAME, null).toInt()
            return numRows
        }
    

提交回复
热议问题