Thursday, April 16, 2020

JDBC: Check if the record exists in the database


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.

if (!resultSet.isBeforeFirst() ) {   
   
System.out.println("No data"); } else{ while(resultSet.next()){ resultSet.getString(1);       resultSet.getString(1); …. ….       resultSet.getString(n); } } source: https://stackoverflow.com/questions/867194/java-resultset-how-to-check-if-there-are-any-results

No comments:

Post a Comment

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows