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

Python Certification

 Python course from codebasics  https://codebasics.io/courses/python-beginner-to-advanced?utm_source=infocard&utm_medium=yt&utm_camp...