Cursor cursor = db.query(TABLE_NAME, columns, null, null, null, null, null); if (cursor.moveToFirst()) { do { //do something with each row } while (cursor.moveToNext()); } cursor.close();
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME, null); while (cursor.moveToNext()) { //do something with each row } cursor.close();Here, we execute a raw SQL query and use a while loop to iterate over the rows. The moveToNext() method is called inside the loop to move the cursor to the next row. The android.database Cursor moveToNext() method is part of the Android SDK and does not require any additional package libraries.