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 URLyBird - Maybe my database file come messed !! Helpp me 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 "URLyBird - Maybe my database file come messed !! Helpp me" Watch "URLyBird - Maybe my database file come messed !! Helpp me" New topic
Author

URLyBird - Maybe my database file come messed !! Helpp me

Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

I think my database file came messed or I'm really lost about database schema...
Someone could help me ???


Fernando Franzini - Java Blog
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5131
    
  12

Fernando,

Don't think anybody can help you if you provide so little information. But maybe this thread can point you in the good direction

Good luck,
Regards,
Roel


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

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi Roel

Actually I have so many doubts...that I'm completely....lost....
I'll formated some question here.....
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi for all

This is my assignament:


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

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 actually dont understand and my database file has some strange characteres....
I need help.....

I attachment some printscreen of my databasefile and bold in red...this strange characteres...
1)what's it ???
2) I dont know what mean MAGIC COOK in the begin of file....???



[Thumbnail for data.jpg]

Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Fernando,

The database file looks reasonable to me. The problem is that you are trying to view it in a text editor, when it is a binary database file.

The JavaRanch SCJD FAQ has some generic information on what the magic cookie is used for.

Take a look at the following hex dump of a similar (but not the same) file:

Offset in bytesHex values Ascii equivalent
0000000 0000 0101 0000 9f00 0700 0400 616e 656d  nul nul soh soh nul nul nul 9f nul bel nul eot n a m e
0000020 4000 0800 6f6c 6163 6974 6e6f 4000 0400   nul @ nul bs l o c a t i o n nul @ nul eot
0000040 6973 657a 0400 0700 6d73 6b6f 6e69 0067   s i z e nul eot nul bel s m o k i n g nul
0000060 0001 7204 7461 0065 0008 6404 7461 0065   soh nul eot  r  r a t e nul bs nul eot d a t e nul
0000100 000a 6f05 6e77 7265 0800 5000 6c61 6361  nl nul enq o w n e  r nul bsnul P a l a c
0000120 2065 2020 2020 2020 2020 2020 2020 2020   e sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp
0000140 2020 2020 2020 2020 2020 2020 2020 2020   sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp
0000200 2020 2020 2020 2020 2020 5320 616d 6c6c   sp sp sp sp sp sp sp sp sp sp sp S m a l l
0000220 6976 6c6c 2065 2020 2020 2020 2020 2020   v i l l e sp sp sp sp sp sp sp sp sp sp sp
0000240 2020 2020 2020 2020 2020 2020 2020 2020   sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp sp
0000300 2020 2020 2020 2020 2020 3220 2020 5920   sp sp sp sp sp sp sp sp sp sp sp 2 sp sp sp Y
0000320 3124 3035 302e 2030 3032 3530 302f 2f37   $ 1 5 0 . 0 0 sp 2 0 0 5 / 0 7 /
0000340 3732 2020 2020 2020 2020 4300 7361 6c74   2 7 sp sp sp sp sp sp sp sp nul C a s t l


In this case, the blue text is the magic cookie - as you can see, the 4 bytes (00 00 01 01) are reasonable if you look at them as hex characters, but are meaningless as ASCII strings (nul, nul, soh, soh) - WordPad does not even give you the equivalent strings (0x00 = null), it just prints blanks.

The green text is my schema section. Note that I have more data and different sized fields than your instructions, so do not pay too much attention to the actual data being shown.

The brown text is the very first record to be read.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi Andrew...thanks again...
Now i'm using Notepad++ to see a file....
So....What should I do with the cookie e meta-data scheme ?? Should I validate this values when final user select and run the program ? or just ignore and read the data session ??
Anne Crace
Ranch Hand

Joined: Aug 29, 2005
Posts: 223
Fernando,

Get a hex editor like the one Andrew used in the post above. It will be invaluable to you while you are working on this project. There are a few free ones aout there. A good Google query should return a few of them.


SCJP, SCJD
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

My recommendation is in line with what is in the FAQ entry I mentioned earlier: I would recommend you use this data to validate that the data file is correct before you start working with it.

Regards, Andrew
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Yeahh I read and I'll validate...Thanks
Julio Cesar Marques
Ranch Hand

Joined: Mar 21, 2009
Posts: 66
Hi Fernando!
Hey look this link it is a "problem solver"
SCJD

I Hope it Help!

Regards!


Julio Cesar Lopes Marques
Sun Certified Java Developer 5, Sun Certified Java Programmer 5
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Thanks for the tip Julio....but I've already read.......twice !!!
phung duc tho
Greenhorn

Joined: Apr 26, 2009
Posts: 2
you can upload databasefile using text to replace image.
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

What do you mean
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Fala Fernando!

Were you able to read your .db file already? I created a simple tool (you can find it here) that reads the .db file and prints its content on the console. Take a look at it if you still didn't get to read it. I think it might be helpful!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
phung duc tho
Greenhorn

Joined: Apr 26, 2009
Posts: 2
Can you upload db file
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

phung duc tho wrote:Can you upload db file


Champion, do you have one of the assignments? If so, you should have a .db file, which you can read with this tool. If not, unfortunately this file cannot be shared with other people.
Also, please take a look at an important administrative private message I just sent you.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: URLyBird - Maybe my database file come messed !! Helpp me
 
Similar Threads
Getting IO exception with doPost is executed
Help with reading text containing non-ascii character
Drag n Drop Question
SCJP Regex Query
what actually context is in Simpler terms?