Forums Register Login
How to write a generic table model for resultset access ?
Fellow Ranchers,

I would like to hear your opinions regarding the best way to implement a generic table model which provides access to resultsets queried from a database.

I know that when implementing a concrete class which extends the AbstractTableModel abstract class, I can provide the source data as an array.

However, when using database queries as source of data such array loading process may take a long time, so I decided to write a generic table model which gets in its constructor a reference to the ResultSet object containing the source data.

Could you please evaluate the below code and give me your thoughts.

It's very important for me, that's why I really appreciate your comments.

I also would really appreciate if you could also evaluate the java naming conventions. (In this topic I'm not sure if I am strict following such conventions)

Edisandro Bessa.

[ September 28, 2006: Message edited by: Edisandro Bessa ]
In getRowCount(), you return 0 when you catch an exception. If the query did not return any rows, the calling method won't know the difference between 0 rows in ResultSet or SQLException occured. The practice I follow is to return some unexpected value, say -1. You can also throw the exception from getRowCount() and handle it in calling method.
Thanks a lot Chandra for your prompt reply.

Well, regarding the getRowCount() method, I'm not allowed to throw exceptions just because the overriden method in the base abstract class do not throw any checked exceptions. So, throwing checked exceptions from my concrete class implementation generates a compile error.

That's why I decided to catch them from within each method.

Regarding the value zero returned from both getRowCount() and getColumnCount() methods, once this class will internally be used by a JTable, there wouldn't be any difference in following your suggestion and return the value -1 instead of 0 ?

Oh, regarding the java naming conventions, specially the code comments with // and /* */, are they correct ? Is there even another elegant way to put such comments in my code ?

Awaiting for your replies.

Best Regards,
[ September 28, 2006: Message edited by: Edisandro Bessa ]
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

All times above are in ranch (not your local) time.
The current ranch time is
Oct 17, 2017 07:27:16.