Solved

Drop recordset into Vector

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java virtual machine monitoring tools 3 39
array11 challenge 16 51
JAVA part two 5 40
compre toata in where clue oracle 4 41
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now