aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes DB file reading problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "DB file reading problem" Watch "DB file reading problem" New topic
Author

DB file reading problem

Vrinda Werdel
Ranch Hand

Joined: Jan 03, 2004
Posts: 75
Hi Guys,

I am doing the following to read the db file. Below is my schema sepc.
*******************************************
Start of file
4 byte numeric, magic cookie value identifies this as a data file
4 byte numeric, offset to start of record zero
2 byte numeric, number of fields in each record

Schema description section.
Repeated for each field in a record:
2 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
2 byte numeric, field length in bytes
end of repeating block
*******************************************

raf.readShort()

The problem I have is when I try to print the "length in bytes of field name ", it prints 0. without this I can not make sense of the contents of the record. However, when I execute the last print statement, it prints the entire record correctly. Am I missing something ? Any input is appreciated.

thanks

Vrinda
Clemens Tolboom
Greenhorn

Joined: Feb 15, 2005
Posts: 12
Your readShort reads the deleteFlag.

Seeking to offset results in skipping the field defnitions which are nice to read if you want a more generic app.
Frans Janssen
Ranch Hand

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

Furthermore, if you are attempting to read the schema (as your code suggests), you should surely not seek to the first record. The schema data is located before all the record data and immediately behind the field that contains the offset to the first record.

Thus, just omit the seek call and you'll probably be fine.

Alternatively, if you don't want to read the schema, but instead hardcode the field sizes in your code, then keep the seek, but don't expect the first short to be the field size; field sizes are only specified once in the schema and are not repeated in the individual records. As Clemens already indicated, the first short in the record will probably be the delete status flag. (The database formats vary between assignments, so I cannot tell for sure without seeing your instructions.)

Frans.


SCJP 1.4, SCJD
Vrinda Werdel
Ranch Hand

Joined: Jan 03, 2004
Posts: 75
Clemens and Frans,

Thanks for your inputs. I am clearly able to visualize the file structure now. Your responses definitely hepled me move fwd.

Thanks

Vrinda
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DB file reading problem