aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Help on the data Sun provided (B&S read method) 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 "Help on the data Sun provided (B&S read method)" Watch "Help on the data Sun provided (B&S read method)" New topic
Author

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

efoe akolly
Greenhorn

Joined: Jun 11, 2003
Posts: 17
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

Joined: Sep 28, 2005
Posts: 225
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) ?


Regards,<br />Seb<br /> <br />SCJP 1.4
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

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


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
efoe akolly
Greenhorn

Joined: Jun 11, 2003
Posts: 17
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

Joined: Jun 11, 2003
Posts: 17
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

Joined: Mar 28, 2003
Posts: 11460
    
  94

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

Joined: Jun 11, 2003
Posts: 17
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

Joined: Mar 28, 2003
Posts: 11460
    
  94

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

Joined: Jun 11, 2003
Posts: 17
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

Joined: Mar 28, 2003
Posts: 11460
    
  94

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
 
 
subject: Help on the data Sun provided (B&S read method)