?
Solved

Need to return multiple instances

Posted on 2003-02-21
5
Medium Priority
?
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 …
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:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

801 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