File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes get the result set in to the vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "get the result set in to the vector" Watch "get the result set in to the vector" New topic

get the result set in to the vector

Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
i,am trying to get ther databse records into a vector should i goabout it needed

Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
Vector rs = new Vector();
Josh Johnson

Joined: Jan 15, 2001
Posts: 20
I don't think Adrian's solution will work. returns a boolean indicating whether there is another record in the ResultSet. does not return the next record in the ResultSet. This solution will not compile because Vector.add expects an Object and returns a primitive.
As far as I know there's no quick and easy way to do what you want. ResultSets can be a pain.
What I would do is write a class that has instance variables for each column in the table. Then step through the resultset with a while loop. In the loop perform these three steps. 1) Create an object (of the class you wrote) for the current row. 2) Transfer the data in the row from the ResultSet to the object (using ResultSet.getXXX). 3) Add the object to the vector (using Vector.add).
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974

[This message has been edited by Thomas Paul (edited February 13, 2001).]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
For each row of record read, loop through the columns adding them to an array, then add the array of columns to your vector.

So much trouble in the world -- Bob Marley
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
I think that's what my code does, doesn't it?
It is sorta covered in the JavaRanch Style Guide.
subject: get the result set in to the vector
Similar Threads
Problem: String != String
ArrayList and Vector
creating variables in a loop
can you have an array of vectors
struts 1.* sedding forms