0

I really need help. I am trying to retrieve a data from in my database using ResultSetMetaData and ResultSet. Also I am using a stored Procedure. The program is run find, however when I run it and be expecting 3 result from the row, instead it will give me 2. For example if I ask a user to enter a position and there are 6 player in that position, it will give me 5 players instead of 6 player.

Here is my code

            if (!rs.next()) {


                System.out.println("There is no match in the database " + position);
            }
            else {
                System.out.println(String.format("  " + " %-19s %s", "Name",
                        "Rank") + "\t" + String.format("%-11s %s", "Position",
                                "School") + "\t" + String.format("%-6s %s",
                                        "Age", "War") + "\n-----------------"
                        + "-------------------------------------------------");
                while (rs.next()) {
                    int rank = 0, age = 0;
                    String name = null, pos = null, sch = null;
                    double war = 0;
                    for (int i = 1; i < colum - 1; i++) {

                        rank = rs.getInt(1);
                        name = rs.getString(2);
                        pos = rs.getString(3);
                        sch = rs.getString(4);
                        age = rs.getInt(5);
                        war = rs.getDouble(6);
                    }

When I run my java code I get this result. It's not getting the first index in the list

When I call my stored procedure in MYSQL Workbench, I get this result

1 Answer 1

3

You have read first index in

    if (!rs.next()) {

itself. This will move the cursor to the next row. You will have to remove this and it will give all the rows.

Sign up to request clarification or add additional context in comments.

1 Comment

That's great! You may accept the answer then if you wish.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.