Assuming you are working with a newly returned ResultSet
whose cursor is pointing before the first row, an easier way to check this is to just call isBeforeFirst()
. This avoids having to back-track if the data is to be read.
As explained in the documentation, this returns false if the cursor is not before the first record or if there are no rows in the ResultSet.
if (!resultSet.isBeforeFirst() ) {
System.out.println("No data");
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…