?
Solved

Need to return multiple instances

Posted on 2003-02-21
5
Medium Priority
?
217 Views
Last Modified: 2010-03-31
I am editing some code where i am return a result set and dumping it into a particular instances of a class.  Right now I am only getting one instances of the class being created.  Previously there was only one record being returned from the DB, but now there is two.  Only one instance is being created though.  

From what I can see this is the method that needs to be dealt with.

Any suggestion welcome!

private void initializeColl(java.sql.ResultSet x) {
     this.x = new Vector(15);
     try {
          while (x.next()) {
               this.x.add(new Amount(
                              x.getString("NAME"),
                              new Double(x.getString("FIRST_AMOUNT")),
                              new Double(x.getString("NEXT_AMOUNT")),
                              x.getString("DATE"),
                              ));
          }
     }
     catch (java.sql.SQLException sqle) {
          sqle.printStackTrace();
     }
}
0
Comment
Question by:ontheball
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 7995122
I don't see anything wrong with your code. Just make sure your expectations are in line with reality!:

private void initializeColl(java.sql.ResultSet x) {
    int rowCount = 0;
    this.x = new Vector(15);
    try {
         while (x.next()) {
              rowCount++;
              this.x.add(new Amount(
                             x.getString("NAME"),
                             new Double(x.getString("FIRST_AMOUNT")),
                             new Double(x.getString("NEXT_AMOUNT")),
                             x.getString("DATE"),
                             ));
         }
     System.out.println("Number of rows returned = " + rowCount);
    }
    catch (java.sql.SQLException sqle) {
         sqle.printStackTrace();
    }
}
0
 
LVL 2

Expert Comment

by:sfotex
ID: 7995902
or try a count query against the dabase before you
get the resultset...
0
 

Expert Comment

by:CleanupPing
ID: 9059156
ontheball:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 9582240
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept CEHJ's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thomas Boshell
EE Cleanup Volunteer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question