aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes db-file question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "db-file question" Watch "db-file question" New topic
Author

db-file question

Peter Aarum
Ranch Hand

Joined: Jan 14, 2010
Posts: 44
Hello fellows!

I am a long time reader but a first time poster to this great forum

I downloaded my assignment, URLyBird and I have some conserns about the db-file.

I have opened this with the encoding of US-ASCII as the instructions stated is was and it looks like this at the beginning of the file. Does this look correct?

Best regards
Peter


[Thumbnail for db.gif]

Carlos Morillo
Ranch Hand

Joined: Jun 06, 2009
Posts: 221

Hi Peter,


Welcome to the SCJD Forum in JavaRanch!


Each assignment is unique to each individual going for the SCJD certificaction.

Please see The Database File Reader Tool in the SCJD FAQ


HTH,


Carlos.


SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
Peter Aarum
Ranch Hand

Joined: Jan 14, 2010
Posts: 44
Thanks for the reply Carlos!

I have tried that and I am a little confused when the result is:
Number of fields in each record: 1311 (if I remember correctly, I dont have the IDE up and running at the moment)

This is my intruction:
Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
2 byte numeric, number of fields in each record

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

Data section.
Repeat to end of file:
1 byte flag. 00 implies valid record, 0xFF implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information

End of file

BR
Peter
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Hi Peter,

Welcome to the JavaRanch!

The file is not a plain text file, hence the squares and funny characters you'll see when opening it with NotePad for example. You could use a HexEditor or just use Roberto's file reader. You can also write your own little database file reader, based on the instructions you got (using a RandomAccessFile or a DataInputStream).
This was my own file reader (of course you'll have to make changes according to your instructions:

Number of fields in each record: 1311
I think that is wrong, because the normal number of fields would be less than 10. Maybe it could be the value of your magic cookie.

Good luck!
Kind regards,
Roel

[edit] changed code snippet according to structure database file


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Peter Aarum
Ranch Hand

Joined: Jan 14, 2010
Posts: 44
Thanks very much for taking the time to help me Roel!

I feel I have to look more in to this. I have tried your app and I cant get it to work properly. I am missing something. I will try more tomorrow. Must sleep now.

Goodnight.

/Peter
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Hi Peter,

Thanks very much for taking the time to help me Roel!
Not a problem at all! One year ago I was in the same position as you: starting with SCJD and I was glad people took the time to help me with my questions, so just giving something back to the community.

At a first glance to the description of your database file your file only has magic cookie and number of fields. My database file has magic cookie, length of a record and number of fields. So try to uncomment lines 12 and 13, and have another shot.

Sweet dreams about SCJD-assignment ;)

Kind regards,
Roel
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2267
    
    3

Howdy, Peter!

Champion, were you able to display the records of your database file already?


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

Joined: Jan 14, 2010
Posts: 44
Hello guys!

Thanks very much for your help guys. Its amazing

SadlyI cant get it to work. I am wondering if this is where I fail
n bytes (defined by previous entry), field name
What does that mean?

BR
Peter
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2267
    
    3

Hey, Peter!

It is the number of bytes that you read just previously.
You couldn't read it, even with the DBFileReader tool?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Roberto Perillo wrote:You couldn't read it, even with the DBFileReader tool?
If the structure of his database file (supplied in one of his previous posts) is consistent with the one from his instructions, it is completely normal he can't read it with your tool, because it seems his database file doesn't have a recordLength (between magicCookie and numberOfFields)

@Peter: i changed my snippet of code to read the database file according to the description you provided in 1 of your earlier posts. Can you give it a try and see of you get any meaningful output?

Kind regards,
Roel
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2267
    
    3

Roel De Nijs wrote:If the structure of his database file (supplied in one of his previous posts) is consistent with the one from his instructions, it is completely normal he can't read it with your tool


Obviously. The only thing different in the format of his schema is that the record length is not informed, so he should be able to read it with DBFileReader with small modifications in the code.
Peter Aarum
Ranch Hand

Joined: Jan 14, 2010
Posts: 44
Thanks Roel that made the trick!

Now I know that there are nothing wrong with the file. (I didnt think it was but....) Now I am gonna studdy this to fully understand it.


Thanks again for all your help!

BR
Peter
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Roberto Perillo wrote:he should be able to read it with DBFileReader with small modifications in the code.
Your DBFileReader is indeed a great tool and these small modifications should make it possible to read his database file:And put every line about recordLength (96, 100, 104, 110, 111) in comment (or just delete them). Now he has 2 programs to read his database file

@Peter
another important note: remember to be sure to have an original copy of your database file, because you have to provide the original copy when submitting (and it is also very useful when you corrupted your file while modifying it)

Kind regards,
Roel
Peter Aarum
Ranch Hand

Joined: Jan 14, 2010
Posts: 44
I have copies all over
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: db-file question