Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to write a generic table model for resultset access ?

 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)

TIA,
Edisandro Bessa.


[ September 28, 2006: Message edited by: Edisandro Bessa ]
 
Cp Baherwani
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Edisandro.
[ September 28, 2006: Message edited by: Edisandro Bessa ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!