How can i get all the values from all the columns?
Ive tried with this code:
values.add(rs.getString(number));
Where number is the rowcount.
But it only gives me all the values from the last column.
I need to grab the values from every column and then add it to the arraylist.
This is my full code:
// The column count starts from 1
int number = 0;
for ( i = 1; i < columnCount + 1; i++ ) {
number++;
ColumnNames = rsmd.getColumnName(i);
ar.add(ColumnNames);
System.out.println(ar);
}
model.setColumnCount(columnCount);
while ( rs.next() ) {
// values.add(rs.getString(ar.indexOf(i)));
values.add(rs.getString(number));
System.out.println(values);
model.addRow(new Object[] {value1, value2, value3, value4});
}
For every rs.next()
:
Object[] row = new Object[columnCount];
for (int i = 1; i <= columnCount; ++i) {
row[i - 1] = rs.getString(i); // Or even rs.getObject()
}
model.addRow(row);