• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX : Help! Error occur in read the data file!

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in my introduce.html:
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.
//my code

And print :
magic cookie value : 259
columnCount = 7
fieldName = name
fieldLength = 64
fieldName = location
fieldLength = 64
fieldName = size
fieldLength = 4
fieldName = smoking
fieldLength = 1
fieldName = rate
fieldLength = 8
fieldName = date
fieldLength = 10
fieldName = owner
fieldLength = 8
fieldFlag : 0
64
64
Dew Drop Inn
fieldFlag : 83
64
64
mallville 4
fieldFlag : 32
4
4
Y$
fieldFlag : 50
1
1
1
fieldFlag : 48
8
8
.00 2005
fieldFlag : 47
10
10
05/02
fieldFlag : 32
8
8
What's wrong with my code?
 
Jamy Wang
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
help
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by james wang:
help


Hi James--
It looks like the byte pointer is off after the first for-loop iteration in that infinite while loop. Why don't you confirm its location after the readFully operation so you know it actually read in what you expected?
Regards,
Paul
 
Jamy Wang
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply ,Paul.
I don't understand why the point to will be incorrect.
I got the first "field Flag" as 0 , but I got the second flag as 83??
What's the wrong with my code? What should be done?
I read the instructions.html file, it said :
//////////////////
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.
//////////////////////
each field fixed length at maximum specified in schema information ,so i use readFully() to read the data into the byte array.
Anyone who could help me ? Thanks in advance!
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James,
had a quick look at your problem.
It looks like you are reading the flag every time you read a field instead of for each record.
Can you try to change your code to:
while(true) {
pt("fieldFlag : "+db.readByte() );
for(int i =0;i<columnCount;i++){
and see what happens?
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Filip,

and see what happens?


I bet with you that the file will look OK.
Well, I am a bit ashamed of it, but I spent twice 3 minutes on that code snippet without pointing the issue ...
Thank you for having solved the problem.
Best,
Phil.
 
Paul Tongyoo
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Filip Moens:
...
had a quick look at your problem.
It looks like you are reading the flag every time you read a field instead of for each record.
...



Ack!! You weren't actually supposed to tell him the answer!!!

[ November 10, 2003: Message edited by: Paul Tongyoo ]
 
Jamy Wang
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all! I found out the error just after I post this thread. I'm so careless and made a silly mistake...
Thank you again.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic