• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Field autodetection URLyBird

 
Victor Bucutea
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,


In your DB implementation class, have you ever used, or have tried to use a sort of column auto-detection. My approach so far was to hardcode the field lengths into static variables in my class.

But in further inspecting Sun's notes i've noticed that after each column there are 2 bytes which indicate the field length. Should we use those field lengths or should we code them in our program ?
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Victor!

Champion, do you mean something like reading the information related to the fields in runtime? If so, please take a look at the DBFileReader tool, which is a tool I created to read the database that is provided in the assignment, and has this approach. I myself chose to hardcode the values of each field in an interface that has some constants related to the database, and is also implemented by the Data class.
 
Victor Bucutea
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm...


Although it is not a bad ideea to do read the lengths of the fields by using the first 74 bytes of the file, and parsing each column name and length piece by piece. I think i'll stick with the static variables option. Nowhere in the assignment does it state that the field lengths are subject to change, so that leads me to believe it is a safe approach ... though it can be improved.

There's one more thing i'd like to add in case someone misses it ( like i did in the first place :-) ) :


THE BYTES FROM 4-8 SPECIFY THE LENGTH TO THE FIRST RECORD, COUNTING FROM BYTE 0 OF THE FILE.



Thanks,
Victor
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic