Re: vector addElement



On 31 Jul., 13:59, Lasse Reichstein Nielsen <l...@xxxxxxxxxx> wrote:
korcs <konrad.lind...@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.

It fixed the problem! Thx!

.



Relevant Pages

  • Re: vector addElement
    ... I add the values into it in a loop. ... What happens is that you add the *same* array to the Vector multiple ... Try instead to move the declaration of row_container inside the while-loop. ...
    (comp.lang.java.programmer)
  • Re: "Case" Question
    ... I have a "Select Case MyVar" in which I define the values of an Array according to the value of MyVar. ... I need to use the Array Values in a Loop after End Select. ... move the declaration out of the Select ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Returning a 2 Dimensional Array
    ... but what I want to do is define each element of the array ... in a loop rather than at declaration. ... >function test() { ...
    (alt.php)
  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • RE: Error 3021
    ... Kevin Backmann ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)