• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help on the data Sun provided (B&S read method)

 
efoe akolly
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,
I am still working on the database file Sun provided. (B&S).
In my read method I am doing something like this:


But so far, only one record (the first) is being printed out. Does that mean there is only one valid record (marked 0 for valid and 1 for deleted)?
Please help me out. I don't know if I am doing something wrong.
Help, Help Help please.

Akem

[Andrew: put code between [code] and [/code] UBB tags]
[ October 21, 2005: Message edited by: Andrew Monkhouse ]
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my original db file, all records are valid. (Maybe you can check this by opening the db file in a text editor which can display Hex values.)

Is your recordLength variable ok ?

Have you tried to display all you file (without checking the deleted flag) ?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11887
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Akem,

What happens when you try to read record # 2? (Or any other record for that matter?)

The way I read your code, if the record was deleted then you should get a NullPointerException thrown when you try to print the retrieved values here:(Immediately following this line you have a redundant "return recordValues".)

Are you sure your calling application (presumably some test harness at this stage) is not swallowing an exception?

Regards, Andrew
 
efoe akolly
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
When I try to read record # 2 or # 3 ... I get a NullpointerException.
I am frustrated and I don't know what to do. Please help me.
Thanks
 
efoe akolly
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Seb,
I tried displaying all the records without checking for the validation flag and all the records show up correctly. I don't know what is going on.
Please help me out.
Thanks
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11887
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Akem,

The problem is in the amount of data you are skipping over, namely this line:You are skipping the header correctly, but I am willing to bet that the recordLength is either a value you read from the meta-data or its a value that you computed when reading the schema. Am I correct?

If so, you will not have skipped 1 delete flag per record.

When I tried your code originally (I had to make up code for calculating record lengths since I didn't have your code, so my code might be different) I got the following results:However the point you are skipping to for the second record (0xEC) is incorrect:You could try something like this:However remember that using magic numbers such as adding the "1" there is a bad idea .

Regards, Andrew
 
efoe akolly
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
Thanks for your help. I am going to try your way. And also, I will definitely buy your book and make some of my friends interrested in the cerfication buy it also. Did you address those issues in your book? Did the project you worked on in your book similar to the one Sun gives (like B&S)?
Anyway Thanks a lot Andrew.

Akem
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11887
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Efoe,

The sample project in the book is similar to the current assignments assigned by Sun. However we have had to make some changes to our project so that we do not give away a ready-made solution to the real assignment.

The problem you have encountered is a little too specific to the real assignment, so you wont find the solution to that particular problem in the book. However you will find plenty of the other comments (such as the comments regarding the use of "magic numbers".

Regards, Andrew
 
efoe akolly
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
I tried your solution but it didn't work. I am still getting nullpointer exception for the remaining records. I am still trying to figure out the problem. Thanks for your help anyway.

Akem
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11887
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Akem,

Did you try looking at your file in hex, and printing the locations of where you are seeking to in hex to see if the computed location is correct?

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic