Data file Format
The format of data in the database file is as follows:
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.
-------------------------------------------------
Please tell me how to implement the data access function according to the specified statements.
Thanks a lot
Regards,
Jackson
Regards, Richard
Please tell me how to implement the data access function according to the specified statements.
Regards, Richard
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
1)If I define the required header info in the seperated header file (e.g called Header.java),is it correct or not as follows?
*************************
int magicCookie; //4 bytes
short numField; //2 bytes
byte fieldnameLen; //1 byte
String fieldName; //n bytes
byte fieldLen; //1 byte
byte valid=00;
byte deleted=0xFF; // maybe a error occurs,because " byte 0xFF" is invalid
byte fieldnameLen; //1 byte
String fieldName; //n bytes
byte fieldLen; //1 byte
So if you were trying to generate Value Objects you would presumably have a Value Object for a record, another ValueObject for the schema (possibly containing multiple Value Objects for each "field name" / "field length" pair).
Regards, Richard
How can I organize the data efficiently into a database?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
1 byte flag. 00 implies valid record, 0xFF implies deleted record
Regards, Richard
"I'm not back." - Bill Harding, Twister
Regards, Richard
Regards, Richard
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes.
Regards, Richard
Regards, Richard
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
You will have to loop through the file until you reach it's end, reading in record after record.
Regards, Richard
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Regards, Richard
You will have to loop through the file until you reach it's end, reading in record after record.
Regards, Richard
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
The single night to which this record relates, format is yyyy/mm/dd.
Regards, Richard
The problem is how I can read(or write) to the end of the file.
I wonder if I should use a file pointer and invoke some methods(e.g seek()).
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
In the date field,I want to declare it as Date object,but how can be showed as yyyy/mm/dd format?
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Regards, Richard
1. You are reading fixedlength Strings regardless of whether they are date fields on anything else. You can always convert the String representation of a Date field to the desired Date format.
This means that Java's default Unicode encoding which takes 2 bytes per character is not to be used here and instead 8 bit US-ASCII character encoding scheme should be used.
Regards, Richard
1)Does it mean that I must create a containing readFixedLength() method?
2)Also, when I face the choice of "smoking" ,I may assume the following code presentation:
You mean that the 8 bit US-ASCII char encoding should be used.
Could you please tell me the procedure to implement that?
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Regards, Richard
I'm gonna teach you a lesson! Start by looking at this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|