Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get the result set in to the vector

 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i,am trying to get ther databse records into a vector .....how should i goabout it .....help needed
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vector rs = new Vector();
rs.add(resultset.next());
 
Josh Johnson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[This message has been edited by Thomas Paul (edited February 13, 2001).]
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that's what my code does, doesn't it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic