Re: vector addElement
- From: Lasse Reichstein Nielsen <lrn@xxxxxxxxxx>
- Date: Tue, 31 Jul 2007 13:59:24 +0200
korcs <konrad.lindner@xxxxxxx> writes:
I want to store the rows of an sql query resultset in a vector.
I add the values into it in a loop.
Here is my code:
You are missing the declaration of row_container.
I assume it's
String[] row_container = new String[fields.length];
and is placed outside the while loop.
while (SQLResultSet.next()) {.... fill row_container ...
buffer.addElement(row_container); // adding the string array to the vector
In the row_container I store in each iteration one resultset row.
The problem is, that it seems to me, that the addElement method adds
the row_container to the end of the vector and then changes the value
of all its previous instances.
No. What happens is that you add the *same* array to the Vector multiple
times, and you update that array in your loop.
Try instead to move the declaration of row_container inside the while-loop.
This will ensure that you create a new array for each row.
/L
--
Lasse Reichstein Nielsen - lrn@xxxxxxxxxx
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
.
- Follow-Ups:
- Re: vector addElement
- From: korcs
- Re: vector addElement
- References:
- vector addElement
- From: korcs
- vector addElement
- Prev by Date: Re: vector addElement
- Next by Date: Re: Detecting CPUs and cores
- Previous by thread: Re: vector addElement
- Next by thread: Re: vector addElement
- Index(es):
Relevant Pages
|
|