Meaningless Drivel is fun!
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S Column Names Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S Column Names" Watch "B&S Column Names" New topic

B&S Column Names

Samuel Pessorrusso
Ranch Hand

Joined: Jul 21, 2005
Posts: 164
I'm in doubt about my TableModel. I'm trying to make the GUI independent of database columns, but in my DB interface there isn't a "getSchema()" method. So I'm having a trouble in discovery the columns names in order to show in them my JTable.

I was thinking in a solution� I�m thinking about creating a new Interface that extends the DB interface and that defines a �public String[] getSchema()� method. My Data class would implement this new interface.

Can I do that? Does any one know a better solution?

Andreas Rutvik

Joined: Jul 18, 2005
Posts: 7
Hi Samuel.

If I have understood correct what you mean, this is a solution :

Samuel Pessorrusso
Ranch Hand

Joined: Jul 21, 2005
Posts: 164
My DB interface does not have the "getFieldInfo()". That's why I'm planing to extend the DB interface and add more methods.
Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
Hi Samuel,

You should ask yourself the question if you want to use the field names from the database as column headers in your GUI in the first place. By mere incident, the names in the supplied files are quite readable. But imagine that the database designer had opted for field names such as CntrNm or numEmployees, would you still want to show these in your GUI?

Let your GUI layer determine the look of your application!


Samuel Pessorrusso
Ranch Hand

Joined: Jul 21, 2005
Posts: 164
Very good point! I didn't realize that.
But I still use the database column names and take as an assumption that database column names will be feasible enough to be used in GUI. That will make my application more flexible.
Lara McCarver
Ranch Hand

Joined: Dec 09, 2003
Posts: 118
It really is a bad design to use database column names in the GUI. One improvement on using database column names is to use a resource file in your GUI. In Java, resource files map one string to another. So, you can use the database column names in this file, and map them to the display string.

Here is some code from a resource file which I am currently using (not for the SCJD project, for something at work)

So instead of using "CM_LABEL_ACTIVE", you would use "CustomerID" and map it to "Customer ID". Your GUI app could search for the resource, and only use the database name for the column if you don't find it in the resource file. You could even automatically add a help label which is mapped to help text about the column, i.e. "CustomerID_HELP" could map to a string which explains the required format of the customer ID. Again, you could automatically search for this.

I don't think you need to do any of this for the assignment, just a suggestion if you want to do it the way you are proposing.
Samuel Pessorrusso
Ranch Hand

Joined: Jul 21, 2005
Posts: 164
Ok, i understood. I'm going to make a resource file and my application will search for the column name in this file. If it does not find the mapped string then it will user the real column name.

Thanks for your attention and help!
[ July 22, 2005: Message edited by: Samuel Pessorrusso ]
I agree. Here's the link:
subject: B&S Column Names
jQuery in Action, 3rd edition