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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Db file reader question

Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I am going to start on my assignment. I have a question on the code that reads the db file. Not to get into too much detail (I hope I am not going against the rules, if so, please tell me so), I have a html file with requirements. Among others, it describes a file in a great detail - what fields are there, what is the length in byes of every field, their names and so on. My questions is - this is so specific, is it ok to just hardcode the values in my db reading code? The names, the lengths, and offset could all be hadrcoded as constants, and the code to read the file would be much simpler. I could of course do it dynamically, but does this make any sense? Will the points be cut if I do one or the other?
Posts: 2292
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Raf!

You know, I myself also hardcoded the values. I created an interface called DBConstants that has all the values, and this interface is also implemented by the Data class. But the code that I created for the DBFileReader tool reads the file dinamically, just so everybody can use it, and more people may make use of it.

I justified my choice of hardcoding the values saying that nothing was mentioned about the database schema changing, so I thought there were no problems, and the code would be simpler.
Ranch Hand
Posts: 114
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My motivation was, friend Roberto’s amazing DBFileReader, to go for dynamic file reading
in the assignment.

Now I feel like, probably gone a bit extra than the requirements.
Posts: 11604
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I read my database schema completely dynamically. My main argumentation was it would become very easy to use the Data class (I created for handling the room bookings) to handle a similar file with customers, hotels,... So it makes your Data class completely independent of the database file you are using (without adding too much complexity to the Data class).

Kind regards,
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic