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

Derivatives stock list at NSE

Complete FNO stock list at NSE. ABB India Ltd ACC Ltd APL Apollo Tubes Ltd AU Small Finance Bank Ltd Aarti Industries Ltd Abbott India Ltd A...