This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read a particular record?

 
Karthik Balasubramanian
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I just started working on Bodgitt & Scarper assignment. I wrote a method to read the DB file. It is working fine. But when I read the requirements of the assignment, it says:
"Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:
package suncertify.db;
public interface DB
{
// Reads a record from the file. Returns an array where each
// element is a record value.
public String[] read(int recNo) throws RecordNotFoundException;"
From above, I understood that "public String[] read(int recNo)" method should return the particular record based on the parameter we pass. That is, if we pass 3, it should return just the 3rd record..Is my understanding correct?
If my understanding is correct, can you guys suggest me how to get this done? Because, the db records does not have any index...I dont know how to do this...please help me out on this.
Thanks
Karthik
 
Jay Bromley
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Your understanding of the assignment specification is correct.
You are correct in saying that there are no _explicit_ record indices in the file, but there certainly is an implied record number. The first record would be 0, the second record would be 1, and so on. The header of the database file contains information about the byte offset of the first record, and the lengths of all the data fields, which lets you figure out the length of a record, so putting these two together with a record index number you can calculate the starting offset of any record.
Regards,
Jay
[ December 12, 2003: Message edited by: Jay Bromley ]
 
Bill Robertson
Ranch Hand
Posts: 234
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
think of it in from a math standpoint.
if the header size is 40, and each record is 80, then you know record
1 must start at 40 + (80 * 1). Record 3 must start at 40 + (80 * 3)
and record X must start at 40 + (80 * X).....
 
Karthik Balasubramanian
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill and Jay. It was very helpful.

Karthik
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic