-
Populating a JTable
I'm trying to populate my JTable. I have 3 rows in the table and it's populating one row 3 times. What's wrong with my loop?
Code:
while(rs.next()) {
int count;
for(int i=0; i < numRows; i++) {
count = 1;
for(int j=0; j < numCols; j++) {
familyTable.setValueAt(rs.getString(count), i, j);
count++;
}
}
-
Because every time you read one row from the ResultSet, you update all three rows in the TableModel. So all three rows will contain the values from the last row read in the ResultSet.
-
So what should I change in my code to make this work?