This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
Author

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 .....how should i goabout it .....help needed

Raghav.
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
Vector rs = new Vector();
rs.add(resultset.next());
Josh Johnson
Greenhorn

Joined: Jan 15, 2001
Posts: 20
I don't think Adrian's solution will work. ResultSet.next returns a boolean indicating whether there is another record in the ResultSet. ResultSet.next does not return the next record in the ResultSet. This solution will not compile because Vector.add expects an Object and ResultSet.next 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.
Bosun


Bosun (SCJP, SCWCD)
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