Solved

Drop recordset into Vector

Posted on 2002-05-15
5
349 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 97
diffSum example 4 37
Should localization be done inside spring controller 5 27
Configure a Bean in an XML file 4 33
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 …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

803 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