Solved

Drop recordset into Vector

Posted on 2002-05-15
5
353 Views
Last Modified: 2006-11-17
Hi,

How can I drop a multidimensional recordset into a Vector? I've generated the code for a single field recordset, but need this to store additional fields.


ResultSet rs = stmt.executeQuery("select ID,Name,DOB from aTable where NAME='aName'");

Vector ids = new Vector();
try {
 while(rs.next())
   ids.addElement(rs.getString("ID"));
} catch(Exception e) {}

Best wishes
sabi97

0
Comment
Question by:sabi97
[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
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
BaneBane earned 120 total points
ID: 7010722
Why don't you use a vector which will store an object representing the resultSet.

ResultSet rs = stmt.executeQuery("select ID,Name,DOB from aTable where NAME='aName'");

Vector ids = new Vector();
try {
while(rs.next())

  data.setID(rs.getString("ID"));
  data.setName(rs.getString("Name"));
  data.setName(rs.getString("Dob"));
  ids.addElement(data);
} catch(Exception e) {}

Hope this helps

0
 

Author Comment

by:sabi97
ID: 7010918
Thank you BaneBane for your answer!

If I then needed to display the results, how would I work through the vector with.
 for(int i=0; i< ids.size(); i++){


}

Best wishes

sabi97

0
 
LVL 1

Expert Comment

by:BaneBane
ID: 7010945
You should add getter methods to the data object.
so you should

Data data = null;

for(int i=0; i< ids.size(); i++){

 data = ids.get(i);
 System.out.println("ID=" + data.getID());
 System.out.println("Name=" + data.getName());
 System.out.println("Dob=" + data.getDob());
}

Hope this helps

0
 

Author Comment

by:sabi97
ID: 7010967
Thanks very much BaneBane!

Best wishes

sabi97
0
 
LVL 1

Expert Comment

by:BaneBane
ID: 7010976
Sure
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

636 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