Vector issue in JSP/Tomcat applicaiton

E

E B

Hi All -

I have an app where I'm retrieving records from a database, the
individual column data is being stored into a custom object, which are
put into a Vector (which is basically a row of data from the table),
and then these vectors are added to another vector (vector of
vectors), making up the contents of the table.

However when I add my second vector (row 2 of the data), it appears to
be overwriting the contents of the first row, as well as adding the
second, so I have two vectors (vector.size() is 2 at this point) in my
data vector that are exactly the same.

Has anyone experienced something like this before?

my debugging efforts seem to confirm that the first row vector is put
in my final vector properly.

Any help appreciated.

Thanks.
Eric
 
C

Chris Smith

E said:
However when I add my second vector (row 2 of the data), it appears to
be overwriting the contents of the first row, as well as adding the
second, so I have two vectors (vector.size() is 2 at this point) in my
data vector that are exactly the same.

Has anyone experienced something like this before?

Sounds like you're not creating a second inner Vector at all, but merely
modifying the contents of the first one and then adding it to the outer
Vector again.

If you post some code, perhaps I could verify this.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
S

Sudsy

E said:
<snip>

I strongly suspect that Chris is right. And it is something we see
from time to time. If you don't create a new Vector each time
through the loop then you're merely creating multiple references
to a single Vector. You can't just invoke removeAllElements and
then start rebuilding it.
 
R

Roedy Green

By the way, Vector is obsolescent; use ArrayList instead.

is that similar to it being "grue"? (see Sci Am a long time ago).


a sort of time-dependent opalescence?
 
S

Steven J Sobol

Roedy Green said:
different reference. Grue objects were objects used in logic puzzles
that mysteriously changed between green and blue.

The old ZORK text adventure games on the Apple II used a significantly
different definition for the word "grue."
 
E

E B

Chris -

Thanks for the help. Pointed me in the right direction. I was
actually doing new Vectors, but the problem was my objects in the
loop, I was creating a new myObject but assigning it to an existing
one, thus reusing the same reference.

Thanks again
Eric
 
C

Chris Smith

E said:
Thanks for the help. Pointed me in the right direction. I was
actually doing new Vectors, but the problem was my objects in the
loop, I was creating a new myObject but assigning it to an existing
one, thus reusing the same reference.

Glad your code works now. That doesn't sound like an accurate
description of the problem, though admittedly I only have a vague
understanding at this point of what your code looks like. In any case,
it sounds as if you've potentially got unneeded complexity from trial-
and-error programming, and if you post the code I might be able to give
you a simpler way to solve your problem. That's up to you.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top