I want to get the number of rows from my database How can I create a method that returns the number of rows as an int? Here's what I got but it only returns number 1
public int getAllId() {
SQLiteDatabase db = this.getWritableDatabase();
int x=0;
String where = null;
Cursor c = db.rawQuery("SELECT COUNT (*) FROM " + TABLE_PRODUCTS, null);
while (c.isAfterLast() == false) {
c.moveToNext();
}
db.close();
return c.getCount();
SELECT COUNT(*) FROM MYTABLEinside your method. Show some initiative, there's plenty of information available on these things.preparedStatement.executeUpdate()returns number of rows. Why not to get result inResultSetand iteratewhileuntilresultSet.next()ifresultSet != nulldoes this make sense