How to check if a ResultSet is empty?

1

I am doing a query in MySQL and when the query exists it returns the values of good.

But here's the question, what value does ResultSet receive when the search does not exist? Type searched for a name in the records of the table if that name does not exist in the database what is returned?

I searched the internet but found nothing related.

    
asked by anonymous 11.09.2016 / 21:50

1 answer

0

You can verify that the method ResultSet.html#isBeforeFirst false returns:

con = DriverManager.getConnection( ... );
stmt = con.prepareStatement( ... );

ResultSet rs = stmt.executeQuery();

if (!rs.isBeforeFirst() ) {    
    // Não há dados, faça algo aqui...
} 

The isBeforeFirst will return false if the cursor is not before the first record or if it has no rows in ResultSet , or true otherwise.

    
11.09.2016 / 22:18