Annoying database problem!
Hi,
I was wondering if anyone could help me. After running the below code, I get a SQL Exception "ResultSet is closed" as I leave the while(c.nextPage()) loop - can someone tell me why and also how to stop the exception and instead just get out of the while loop as it's meant to and run the next lot of code?
Thanks.
Code:
public JTable printData (CachedRowSet c){
try{
RowSetMetaData rsmd = (RowSetMetaData)c.getMetaData();
int cols = rsmd.getColumnCount();
String [] columns = new String[cols];
for (int i = 0; i<cols; i++){
columns[i] = rsmd.getColumnName(i+1);
}
c.last();
int rows = c.getRow();
c.first();
String [][] data = new String [rows][cols];
int i = 0;
c.beforeFirst();
while(c.nextPage()){ // ERROR AS LEAVE
// Inner code works fine - populates data as required
while(c.next()){
for (int j = 0; j<cols; j++){
data[i][j] = c.getString(j+1);
}
i++;
System.out.println("c.next");
}
}
DefaultTableModel dm = new DefaultTableModel();
dm.setDataVector(data, columns);
JTable table = new JTable(dm);
return table;
} catch (SQLException e) {
System.err.println("Could not connect: " + e + "\n" + e.getMessage() );
e.printStackTrace();
JTable table = new JTable();
return table;
}
}