Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Drop recordset into Vector

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

715 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