amberdextrous
MIS
Hello all,
I'm developing an app that connects to a database (in my case, an Access database) and can run SQL queries against it (select, insert, delete, etc.). I'm trying to read data from the database using a ResultSet so I can output it to a JTable. There are several tables in the database, and each one has a different # of columns. My problem is when I'm iterating through the Result Set, I don't know how many rows or columns there will be.
I know I can use:
to get the column number, but I can't count the rows because I can't use .first() to go back to the beginning. So, I have to do everything as it iterates.
I figure I need to use an ArrayList and something like this:
But that's where I'm stuck. Anyone know what I should do? I'm really pulling my hair out over this.
I'm developing an app that connects to a database (in my case, an Access database) and can run SQL queries against it (select, insert, delete, etc.). I'm trying to read data from the database using a ResultSet so I can output it to a JTable. There are several tables in the database, and each one has a different # of columns. My problem is when I'm iterating through the Result Set, I don't know how many rows or columns there will be.
I know I can use:
Code:
int columnCount = resultSet.getMetaData().getColumnCount();
I figure I need to use an ArrayList and something like this:
Code:
while(resultSet.next()) {
for (int i = 1; i <= columnCount; i++) {
}
}
But that's where I'm stuck. Anyone know what I should do? I'm really pulling my hair out over this.