Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Drop recordset into Vector

Posted on 2002-05-15
5
Medium Priority
?
358 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 480 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.
Suggested Courses

876 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