• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

getting items stored in a vector?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a vector in which i'm storing a resultSet. Each Element of the resultSet is one row from a db. I need to get the items out of the vector one at a time and place them in a form somewhere.
My problem is I can't seem to figure out how to get the items out of the vector one at a time and place them where they need to go.
This is what I have so far.
try {
ResultSetMetaData rmeta = rsGl.getMetaData();
columns = rmeta.getColumnCount();
colnames = new Vector();
for (int i = 1; i <= columns; ++i) {
colnames.addElement(rmeta.getColumnLabel(i));
}
rows = new Vector();
rows.addElement(colnames);
rowcount = 0;
while (rsGl.next()) {
rowcount = rowcount + 1;
Vector newRow = new Vector();
for (int j = 1; j <= columns; j++) {
value = rsGl.getObject(j);
newRow.addElement(value);
}
rows.addElement(newRow);
}
System.out.println("Capacity " + rows.capacity());
for(int i = 0; i < 25; ++i) {
System.out.println("Vector Item at " + i + ": " + rows.elementAt(i));
}
Iterator vItr = rows.iterator();
while(vItr.hasNext())
System.out.println(vItr.next() + " ");
}
Can anyone point me in the right direction please.....
Thanks
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(I didn't see what type of object "value" was, so I'll just assume it's of a class called "Value"
Use nested loops to walk through the rows.
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A better implementation is to store a ResultSet row in a Hashtable, then store the row in the Vector, and use Enumerations to get the stuff back out. For example:

This won't likely compile, but you should catch my drift. Let us know what you end up with.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic