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 7576439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:55:15+00:00 2026-05-30T16:55:15+00:00

The code below gets the information i require from my database but is not

  • 0

The code below gets the information i require from my database but is not printing out all of the information. Firstly i know it is getting all of the correct information from the table because i have tried the query in sql developer.

public static void main(String[] args) {
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        conn = getConnection();
        String query = "SELECT menu.menu_id, menu_title, dish.dish_id, dish_name, dish_description, dish_price, menu.week_no "
                + "FROM menu, dish, menu_allocation "
                + "WHERE menu.active = '1' "
                + "AND menu.menu_id = menu_allocation.menu_id "
                + "AND dish.dish_id = menu_allocation.dish_id "
                + "AND menu.week_no IN (09, 10, 11)";
        stmt = conn.createStatement();

        rs = stmt.executeQuery(query);
        MenuList list = null;
        while (rs.next()) {
            list = new MenuList(rs);
            System.out.println(rs.getRow());
        }
        for (int pos = 0; pos < list.size(); pos++) {
            Menu menu = list.getMenuAt(pos);

            System.out.println(menu.getDescription());
        }

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            rs.close();
            stmt.close();
            conn.close();
        } catch (SQLException e) {
        }
    }

}

The output from the terminal is as follows:

 3 //Number of rows
 Fish and Chips //3rd row
 Chocolate Cake //2nd row
 //Here should be 1st row
 BUILD SUCCESSFUL (total time: 2 seconds)

Even though it says there are three rows it has only printed the two. Can anybody see if there is a problem with the above?

  • 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-30T16:55:16+00:00Added an answer on May 30, 2026 at 4:55 pm

    It’s hard to be sure without seeing the code for the MenuList class but I don’t think you need to loop over the ResultSet as MenuList does that for you.

    As the MenuList constructor takes the ResultSet in rs as a parameter it probably loops over the ResultSet to create its entries. As you’ve already called rs.next() in the while of your loop the MenuList misses the first result.

    I think you should replace all this:

    MenuList list = null;
    while (rs.next()) {
        list = new MenuList(rs);
        System.out.println(rs.getRow());
    }
    

    With:

    MenuList list = new MenuList(rs);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code below is used to save PostgreSql database backup from browser in Apache Mono
The code below gets the username/password and runs it thru the backend.php script. <?php
The code pasted below gets an exception on the line that says... InputStream in
In the below code, the ListBox gets filled with the names of the colors
I have below is the html code for TD which gets appended after matching
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code below is not working as expected to detect if it is in design
I have this array which gets the last table from a database. However the
please refer to the code below. $dArr = '<script>document.write(volunteerDist);</script>'; $dArr gets the value of
The code below gets the values I have entered for my report parameters in

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.