您可以使用
do ... while循环而不是
while循环,以便
rs.next()在执行循环后调用该循环,如下所示:
if (!rs.next()) { //if rs.next() returns false //then there are no rows. System.out.println("No records found");}else { do { // Get data from the current row and use it } while (rs.next());}或自己计算行数:
int count = 0;while (rs.next()) { ++count; // Get data from the current row and use it}if (count == 0) { System.out.println("No records found");}


