Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Should I hard code field names?

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the GUI, i am providing with the to and from fields,
should i hard code the name of these fields for performing
the search.
Gaurav
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you should get it from the Database each time - so that itbecomes independent of the database, i.e., any additions to the database will automatically reflect in your search.
Its quite straightforward - get the record - get value - in array - get the appropriate index value - put in a collection to eliminate duplicates - add 'any' to the list and pass it to a combo box constructor
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I hard coded the values for my to and from combo boxes and I still got a perfect score on the GUI section.
I agree that this is not the best way to do this. If any new airport codes are added the GUI will have to be modified. However, if you perform a lookup to read every record from the database and get this list you could have performance problems. Specifically, if the database becomes very large and there are still only a few unique airport codes a lot of time will be wasted reading in duplicate codes.
Just something to think about.
------------------

James Nuzzi
SCJP, SCJD, SCWCD
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your question is really, "Should I hard code the names of the database fieldnames in the gui".
The answer would be that you should put the column names in a constant somewhere. They have to be hard coded somewhere.
Of course if your question is "Should I hard code the cities that can be selected", then the answer is no. The way I did it was on startup to get all list of all of the city names using a TreeSet class. Then you could also provide a way for the user to refresh this list from a menu.
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic