• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to write a generic table model for resultset access ?  RSS feed

 
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 ]
 
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 ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!