Two Laptop Bag*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes I am afraid my db file gets problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "I am afraid my db file gets problem" Watch "I am afraid my db file gets problem" New topic
Author

I am afraid my db file gets problem

Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
Hi,
I am doing experiment on reading the db-2x2.db. I found out that the actual record starts at location 72 with length 182 as specified by the instruction: name + location+ specialty... = (32+64+64+6+8+8)
Here is what I see:

record 1 (from location 72-254)
output:
name : Dogs with Tools (by reading the first 32 bytes in the record)
location: Smallvile (by reading the next 64 bytes in the record and so on...)
specialty: Roofing
size: 7
rate: $35
owner:

record 2 (from location 254-436)
output:
name: Hamner&Tong
location: Smallvile
specialty : Drywall, Roofing
size: 10
rate: $85
owner:

record 3 (from location 436-618)
output:
name: Phil Remodeling
location: Whovile
Specialty: Roofing
size : 3
rate: $75
onwer: 00

record 4(from location 618-800)
output:
name : Fred & Nobbs (read 32 bytes)
location: Whoville (read next 64 bytes)
specialty: plumbing, heating (read next 64 bytes)
size: (read next 6 bytes, but don't get any character)
rate: 7 $1 (read next 8 bytes, the size 7 end up within this 8 bytes)
owner: 00.00


I am afraid that the db file has issue with putting the correct field in the correct bytes' sector. I did not change the original db file.


Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
I figured out the issue in the db file.
I output one of the record:
name: Bitter Homes & Garde
location: ns Metropolis
size:
rate: 6 $65.00

In the file, there are too many space that cause the issue. For example, here is :

This is why it prints the first 32 bytes of characters from Bitter Homes & Garde
and then it prints ns Metropolis for the next 64 bytes.

I am not supposed to change db file provided and I am using Monkhouse's approach to read the records base on the total record length. What should I do?
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
I think I know why.
The first record actually starts from 70 to 254, length = 184 because each record has a 2 byte valid flag.
So, reading should be:
from 70 to 254
from 254 to 438
from 438 to 622
from 622 to 806
from 806 to 990
and etc.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5139
    
  12

Helen Ma wrote:I think I know why.
The first record actually starts from 70 to 254, length = 184 because each record has a 2 byte valid flag.

Exactly, that's the problem


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: I am afraid my db file gets problem
 
Similar Threads
Data File Format and reading header information
All numeric values are stored in the header information
question regarding to the data file format
B&S:db format question
Data File Format & Schema File