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

Vector Values

 
Pol Appan
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a vector called v1 and I am loading values to the vector from a resultset.

--while ((getDet_hasData)&&(Repeat1__numRows-- != 0)) {
--v1.addElement(getDet.getObject("EMAIL")+",");
------- some code
)
where getDet is name of the resultset.

I am iterating the loop
Object vect;
String str = "";

for(int i=0;i<v1.size();i++) {
vect = v1.get(i).toString();
str = (String)vect;
bean.setStrValues(4,str);

}
setStrValues is a method in the bean and passing the value.

My problem is I am getting only the last value in my method, after the for loop I have other code to process. Since I am taking the value in the vector and I am iterating I should get all the values, rather than the last values.

What could be the problem and how can I solve it. Please help me

Any help is highy appreciated.

Thanks

Cosmos
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like it should work, although it appears that the code could use some simplification. Send the other code if possible; use the UBB Code tags to help make it more readable.

-Jeff-
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're calling the setStr method with each value from the Vector, but each one replaces the prior value so you only see the last one. Maybe you could build up a single string with all the values in your loop and call setStr after the loop.

You'll have to work out the spaces and commas and such to make allValues look nice, but something like that oughtta work.
 
Pol Appan
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to everyone for pointing out the problem.

I will try.

Thanks

Cosmos
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic