add to arrayList in resultSet
Hello Everyone:
My ResultSet has 1 column and 2 rows with string values (names) ABC and XYZ. I want to add these values in an arrayList, so I did the following. I am showing only the relevant code
int numberOfColumns = rsmd.getColumnCount();
while(rs.next())
{
multiElement.add(rs.getObject(numberOfColumns));
}
when I print the arrayList I see:
multiElement : [ABC]
multiElement : [ABC, XYZ]
multiElement : [ABC, XYZ, ABC]
multiElement : [ABC, XYZ, ABC, XYZ]
The correct output should be simply
multiElement : [ABC, XYZ]
How could I correct the output. Using multiElement.clear() in the while loop also did not help.
Thanks for your help!
add to arrayList in ResultSet
Within the while loop by using
System.out.println("multiElement : " + multiElement) after adding to multiElement