Checking results values using Java ResultSet

0 votes

How can I check the whether there are any more values in the ResultSet as it doesn't contain any method such as hasNext()?

I tried using the below, but not sure whether it is correct or not. Please suggest.

if (!resultSet.next() ) {
    System.out.println("no data");
} 
Aug 16, 2018 in Java by anto.trigg4
• 3,440 points
819 views

1 answer to this question.

0 votes

As per my knowledge what you are doing is partially correct.

Because, initially, the ResultSet's cursor will be pointing to before the first row. Now, if the first call to next() returns false then there is no data in the ResultSet. So, you will also have to call beforeFirst() immediately in order to reset it. 

if (!resultSet.isBeforeFirst() ) {    
    System.out.println("No data"); 
} 
answered Aug 16, 2018 by code.reaper12
• 3,500 points

Related Questions In Java

0 votes
2 answers

How can I sort values of a Map in Java using its key

Assuming TreeMap is not good for you ...READ MORE

answered Oct 10, 2018 in Java by Sushmita
• 6,920 points
1,205 views
0 votes
2 answers

How do I get the current date and time using Java?

If you require a time stamp in ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 59,230 points
2,933 views
0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,220 points
2,923 views
0 votes
1 answer

How can I read a large text file line by line using Java?

// Open the file FileInputStream file = new ...READ MORE

answered May 2, 2018 in Java by Parth
• 4,640 points
894 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,222 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
8,358 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
17,432 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points

edited Aug 4, 2023 by Khan Sarfaraz 4,875 views
0 votes
1 answer

JSON parsing in Java using Gson

Well, you can easily do that by ...READ MORE

answered Nov 22, 2018 in Java by code.reaper12
• 3,500 points
1,998 views
0 votes
1 answer

Purpose of “String args[]” in the “psvm” of Java

Let me give you the complete explanation ...READ MORE

answered May 7, 2018 in Java by code.reaper12
• 3,500 points
4,703 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP