If I understand your purpose, you can use the do while
if (!results.next()) { System.out.println("empty"); } else { //display results do { String data = results.getString("first_name"); //name.setText(data); System.out.println(data); } while (results.next()); }
Or you can just save count so
int count = 0; //display results while (results.next()) { String data = results.getString("first_name"); //name.setText(data); System.out.println(data); count++; } if (count < 1) { // Didn't even read one row }
source share