Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4026374
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:57:45+00:00 2026-05-20T10:57:45+00:00

I want to get the size of the ResultSet inside the while loop. Tried

  • 0

I want to get the size of the ResultSet inside the while loop.

Tried the code below, and I got the results that I want. But it seems to be messing up with result.next() and the while loop only loops once if I do this.
What’s the proper way of doing this?

result.first();
while (result.next()){

    System.out.println(result.getString(2));
    System.out.println("A. " + result.getString(5) + "\n" + "B. " + result.getString(6) + "\n" + "C. " + result.getString(7) + "\n" + "D. " + result.getString(8));
    System.out.println("Answer: ");
    answer = inputquiz.next();

    result.last();

    if (answer.equals(result.getString(10))) {
        score++;
        System.out.println(score + "/" + result.getRow());
    } else {
        System.out.println(score + "/" + result.getRow());
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:57:45+00:00Added an answer on May 20, 2026 at 10:57 am

    What’s the proper way of doing this?

    Map it to a List<Entity>. Since your code is far from self-documenting (you’re using indexes instead of column names), I can’t give a well suited example. So I’ll take a Person as example.

    First create a javabean class representing whatever a single row contains.

    public class Person {
        private Long id;
        private String firstName;
        private String lastName;
        private Date dateOfBirth;
    
        // Add/generate c'tors/getters/setters/equals/hashcode and other boilerplate.
    }
    

    (a bit decent IDE like Eclipse can autogenerate them)

    Then let JDBC do the following job.

    List<Person> persons = new ArrayList<Person>();
    
    while (resultSet.next()) {
        Person person = new Person();
        person.setId(resultSet.getLong("id"));
        person.setFirstName(resultSet.getString("fistName"));
        person.setLastName(resultSet.getString("lastName"));
        person.setDataOfBirth(resultSet.getDate("dateOfBirth"));
        persons.add(person);
    }
    
    // Close resultSet/statement/connection in finally block.
    
    return persons;
    

    Then you can just do

    int size = persons.size();
    

    And then to substitute your code example

    for (int i = 0; i < persons.size(); i++) {
        Person person = persons.get(i);
        System.out.println(person.getFirstName());
        int size = persons.size(); // Do with it whatever you want.
    }
    

    See also:

    • How to check if there is zero-or-one result or one-or-more results and their size
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In mssql2005 when I want to get size of table in MBs, I use
I want to get the size of the current terminal, i.e. the terminal my
In my project I want to get the size from the greatest homogeneous area
i want to create functions what get the folder size. I write small function:
I want to know how to get the total size of the modified files
I want get all of the Geom objects that are related to a certain
What I want: get a xml from the AppData to use What I code
I'm trying to place various size images inside imageView of UITableViewCell. I get the
I want to get the results of a left join between two tables, with
Is it possible to get the size in bytes of the results of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.