0

I am validating if a resultset is empty. if it is empty send a message, but if you have data to show them. But he only sends me the second value, the first one is lost

if (!rs.next()){
    JOptionPane.showMessageDialog(null, "The rs is empty");
}else{
    while(rs.next()) {
    OptionPane.showMessageDialog(null, rs.getString(1));**//only show the second data**
    }
}

2 Answers2

1

Replace your code with the following:

if (!rs.next()){
    JOptionPane.showMessageDialog(null, "The rs is empty");
}else{
    do {
        OptionPane.showMessageDialog(null, rs.getString(1));
    }while(rs.next());
}
Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
0

Replace your code with the following:

boolean empty = true;
while (rs.next()) {
    empty = false;
    OptionPane.showMessageDialog(null, rs.getString(1));
}
if (empty) {
    JOptionPane.showMessageDialog(null, "The rs is empty");
}
Andreas
  • 154,647
  • 11
  • 152
  • 247