Hi
I've written a TableModel to support my JTable. It takes a CachedRowSet in its constructor, since this is the data I am trying to show.
The CachedRowSet does not seem to have a method to move the cursor to an arbitrary row, even though all the data is in memory, which is peculiar. So, in the getValueAt method, I think I only have two approaches.
1. Move back to the first record, and count down to the requested row. This is what I currently am doing. I guess I could make it more efficient by checking if the row is the same as the last time the method was called, or if it is just the next one, in which case I don't have to move back to the start.
2. Hold the data in an array or vectors or whatever. This seems inefficient because the data is taking up memory twice.
Has anyone any better ideas? Here is my current code. You can see I have another issue in the code with throwing exceptions back to the caller, but I am not so worried about that right now.
Thanks
Mark
I've written a TableModel to support my JTable. It takes a CachedRowSet in its constructor, since this is the data I am trying to show.
The CachedRowSet does not seem to have a method to move the cursor to an arbitrary row, even though all the data is in memory, which is peculiar. So, in the getValueAt method, I think I only have two approaches.
1. Move back to the first record, and count down to the requested row. This is what I currently am doing. I guess I could make it more efficient by checking if the row is the same as the last time the method was called, or if it is just the next one, in which case I don't have to move back to the start.
2. Hold the data in an array or vectors or whatever. This seems inefficient because the data is taking up memory twice.
Has anyone any better ideas? Here is my current code. You can see I have another issue in the code with throwing exceptions back to the caller, but I am not so worried about that right now.
Thanks
Code:
public Object getValueAt(int row, int col) {
//unfortunately, there does not seem to be a method in the CachedRowSet to do this, so it seems that the way is
//to move back to the start of the set, and count down the rows. That sucks - there must be a better way - we have all the
//data in memory, for Pete's sake!
//again, similar to getColumnName - a flag
Object o = "#Error in getValueAt for row " + row + " and col " + col;
try{
m_crs.first();
for (int i = 1; i <= row ; i++)
{
m_crs.next();
}
o = m_crs.getObject(col + 1);
}
catch (Exception e)
{
m_client.ErrorOccured(e);
}
return o;
}
Mark