I am iterating over an ResultSet and trying to copy its values in an ArrayList.
The problem is that its traversing only once. But using resultset.getString("Col 1") to resultset.getString('Col n") is showing all entries of all columns.
Below is the code snippet -
ResultSet resultset = null;
ArrayList<String> arrayList = new ArrayList<String>();
int i = 1;
while (resultset.next()) {
arrayList.add(resultset.getString(i++));
System.out.println(resultset.getString("Col 1"));
System.out.println(resultset.getString("Col 2"));
System.out.println(resultset.getString("Col n"));
}
The only value of ResultSet getting copied into ArrayList is for column 1. And then while exits.
But I can see the value of all columns.
Why?