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

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...