jQuery in Action, 2nd edition*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Field autodetection URLyBird Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Field autodetection URLyBird" Watch "Field autodetection URLyBird" New topic
Author

Field autodetection URLyBird

Victor Bucutea
Ranch Hand

Joined: Nov 24, 2008
Posts: 43
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

Joined: Dec 28, 2007
Posts: 2258
    
    3

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.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Victor Bucutea
Ranch Hand

Joined: Nov 24, 2008
Posts: 43
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Field autodetection URLyBird
 
Similar Threads
Looking for some nice advice
Question on sum of syracuse sequence (memorization question)
Data conversion tool
NX:How to avoid hard coding?
NX: how to obtain data and column names at client