File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Database file reader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Database file reader" Watch "Database file reader" New topic
Author

Database file reader

Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2246

Howdy, Greg.

Alright, good news! I'm glad this was helpful! The idea is just to get you started, so the goal was achieved!

When you are done with the development of the Data class, you might also want to take a look at the Tests for the Data Class/Locking Mechanism tool. It will help you test your Data class and mainly your locking mechanism. I think it will also be helpful!


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

Joined: Feb 09, 2011
Posts: 81

I appreciate the code Robert. I am sure it will come in handy.

Cheers,
Greg Funston SCJP
Venkat Chadaram
Greenhorn

Joined: Jan 25, 2008
Posts: 3
Excellent! Tool. Downloaded SCJD exam - Couldnt get my head around the db file. This tool worked against my db file without any changes. Thanks a ton. Had I got this tool in 2007 I would have had all Sun Developer exam certifications. This is the only Developer exam I don't have yet.


Venkat Chadaram<br />SCJWSD <br />SCBCD <br />SCJP 1.4
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2246

Alright, Venkat! I'm very glad this was helpful to you!
Alexandra Zhang
Greenhorn

Joined: Jun 08, 2007
Posts: 16
Thank you very much Robert.

I just finished reading your paper and trying to start with the implementation following your implementation steps this afternoon. I'm working on URLyBird 1.1.2.

And your DBFileReader works so well to me. The only change I made are the constant values of RECORD_FLAG_BYTES, and DATABASE_LOCATION. From this class I learned both implementations and the coding style you've showed.

I'm quiet a novice in Java. Hopefully I would learn and make a great deal of improvements after finishing this assignment.

hmontiel montiel
Greenhorn

Joined: Aug 07, 2007
Posts: 2
Hi guys,

I think the tool is great but I was not able to use it because apparently has a fixed column name length, and for the URLyBird 1.1.3 version the column name are flexible defined on one on the columns.

This is the definition of the 1.1.3 .db file:

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

All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.

Database schema
The database that URLyBird uses contains the following fields: Field descriptive name Database field name Field length Detailed description
Hotel Name name 64 The name of the hotel this vacancy record relates to
City location 64 The location of this hotel
Maximum occupancy of this room size 4 The maximum number of people permitted in this room, not including infants
Is the room smoking or non-smoking smoking 1 Flag indicating if smoking is permitted. Valid values are "Y" indicating a smoking room, and "N" indicating a non-smoking room
Price per night rate 8 Charge per night for the room. This field includes the currency symbol
Date available date 10 The single night to which this record relates, format is yyyy/mm/dd.
Customer holding this record owner 8 The id value (an 8 digit number) of the customer who has booked this. Note that for this application, you should assume that customers and CSRs know their customer ids. The system you are writing does not interact with these numbers, rather it simply records them. If this field is all blanks, the record is available for sale.

I created the following printer (please forgive the terrible OO design and coding standards) I did it in 35 minutes to visualize the .db file so I didn't spent too much time in making it reusable, and it probably will only work on the 1.1.3 version of URLyBird.

Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2246

Howdy, Hmontiel. Welcome to JavaRanch!

Well champ, what happens if you set the FIELD_NAME_BYTES variable to 1?
hmontiel montiel
Greenhorn

Joined: Aug 07, 2007
Posts: 2
Roberto Perillo wrote:Howdy, Hmontiel. Welcome to JavaRanch!

Well champ, what happens if you set the FIELD_NAME_BYTES variable to 1?


Hi Roberto,

Thanks for the welcome, my bad, didn't quite got the comments on the settings after carefully reading them.
It required of adjustments, this is how the settings work for 1.1.3 URLyBird version (bold the changes):



Works great!
By the way excellent document "Demystifying the OCMJD Certification".

-Hector
Alexandru Dragoi
Greenhorn

Joined: May 09, 2008
Posts: 29
Related to this code:



What can you use to for filling up unused bytes for each field up to a specified length? Can you use blancks, or can you use something like this:


and when reading, you can do something like this:


Alex Dragoi, SCJP 1.4, OCPJP 6
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4907
    
  10

I used something like this:


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

Joined: Apr 18, 2013
Posts: 590
    
  11

I used spaces (\u0020). Why? Because the db file provided to me already used this approach. And as I noted in choices.txt I would not expect any field beginning with spaces I just justified using of String.trim() when reading data ;).
Alexandru Dragoi
Greenhorn

Joined: May 09, 2008
Posts: 29
Pawel Pawlowicz wrote:I used spaces (\u0020). Why? Because the db file provided to me already used this approach. And as I noted in choices.txt I would not expect any field beginning with spaces I just justified using of String.trim() when reading data ;).


Ohh...so I guess it depends on the database file you receive with your assignment. You can read it with the tool provided by Roberto and then you can figure out what they used to fill out the unused bytes...
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4907
    
  10

Alexandru Dragoi wrote:Ohh...so I guess it depends on the database file you receive with your assignment.

There is in the instructions a statement that says that the file is also used by another application. So you could use that as an argument to keep the same padding character (as you don't know if the other application can handle another padding char).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database file reader
 
Similar Threads
db-file question
Coding Convention - comments
working with the DataBase
How do I get the delete flag to display in the right format
B&S: Data File Format