K
korcs
Hi,
I have a problem with using a Vector.
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:
while (SQLResultSet.next()) {
// buffering one row
for(int i=0; i<fields.length; i++) {
//the row is stored in a string array
row_container = SQLResultSet.getString(fields);
}
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.
So the content of the vector (after 1,2,3,4 loops) is like:
First loop:
1 | snake | reptile
Second loop:
2 | frog | amphibian
2 | frog | amphibian
Third loop:
3 | tuna | fish
3 | tuna | fish
3 | tuna | fish
Forth loop:
4 | racoon | mammal
4 | racoon | mammal
4 | racoon | mammal
4 | racoon | mammal
Instead of:
First loop:
1 | snake | reptile
Second loop:
1 | snake | reptile
2 | frog | amphibian
Third loop:
1 | snake | reptile
2 | frog | amphibian
3 | tuna | fish
Forth loop:
1 | snake | reptile
2 | frog | amphibian
3 | tuna | fish
4 | racoon | mammal
Could you tell me how could i get the latter result?
Thx.
Best,
korcs
I have a problem with using a Vector.
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:
while (SQLResultSet.next()) {
// buffering one row
for(int i=0; i<fields.length; i++) {
//the row is stored in a string array
row_container = SQLResultSet.getString(fields);
}
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.
So the content of the vector (after 1,2,3,4 loops) is like:
First loop:
1 | snake | reptile
Second loop:
2 | frog | amphibian
2 | frog | amphibian
Third loop:
3 | tuna | fish
3 | tuna | fish
3 | tuna | fish
Forth loop:
4 | racoon | mammal
4 | racoon | mammal
4 | racoon | mammal
4 | racoon | mammal
Instead of:
First loop:
1 | snake | reptile
Second loop:
1 | snake | reptile
2 | frog | amphibian
Third loop:
1 | snake | reptile
2 | frog | amphibian
3 | tuna | fish
Forth loop:
1 | snake | reptile
2 | frog | amphibian
3 | tuna | fish
4 | racoon | mammal
Could you tell me how could i get the latter result?
Thx.
Best,
korcs