Search code examples
javaif-statementwhile-looprecordset

Java - Unable to read inside the recordset contained with if else statement


I have a piece of java code that I am not sure as to why I am not getting any results from it. The code goes as such:

if (!ReminderList.next()) {
    -- Show that there are no records available
} else {
   while (ReminderList.next(){
      -- Show that there are record
      System.out.println(ReminderList.getString("ReminderID"));
   }
}

The if..else condition works perfectly and if there are records, the system does enter the else system. However, it does not enter the while loop. What am I missing?


Solution

  • You have already called next() once (in the if). I think the easiest solution is to change the else to a do-while like,

    do {
      // -- Show that there are record
      System.out.println(ReminderList.getString("ReminderID"));
    } while (ReminderList.next());