File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes field for record number in database file? 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 "field for record number in database file?" Watch "field for record number in database file?" New topic

field for record number in database file?

prakash bayas

Joined: Apr 09, 2011
Posts: 2
i am writing subcontractor assignment. in this, i wrote the interface db and class data implementing this interface only.
In the book, Denny's dvd application, gui controllers method for finding with search criteria returns list of dvds. this is because this method returns list of dvd objects. but as per the interface provided, in this method for subcontractor, i am returning first int[] of record numbers matching search criteria and for every number read(recNo)ing record.
when i am matching say Dogs With Tools, able to filter records with this string but how should i identify these obtained records with unique record number as this field is not present in database.
when application starts record numbers will be displayed in sequence 1, 2 but this sequece get changed for new filtered results and a call to read with these new record numbers return different records.
also, how should i increment this recNo field, as of now i am hardcoding this in retrieveSubcontractor(long locationInFile) method of SubcontractorFileAccess class.
the book from andrew and terry, for this certification, has helped a lot along the way!, have never done multithreading before this book!
Roberto Perillo

Joined: Dec 28, 2007
Posts: 2271

Howdy, Prakash. Welcome to JavaRanch!

Champ, sorry but I didn't quite get your question... what exactly is your doubt? Could you please elaborate it a little better?

Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roel De Nijs

Joined: Jul 19, 2004
Posts: 8372

I think he has a little bit doubts about what he should use as a record number to identify each reacord in the database file. I would say just use a logical record number. That means the 1st record in the database has 0 as record number, the 2nd one has 1 and so on.

In your find-method you will return an array with the matching records. So if the 1st, 3rd and 4th record match the specified criteria the method will return an array containing 0, 2 and 3. So you use the record numbers corresponding to the position of the record in the database file (and NOT the record number corresponding to the position in the filter results)

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
Matthew McDonald

Joined: Apr 10, 2011
Posts: 6
i am doing the same project for my diploma, and the database file itself doesn't have a recNo field.. fields are; name, location, specialties, size, rate and owner.
i am having the same problem... i am thinking of having a "database" class that creates an instance of the database by reading the data from an inputStream... and adding the recNo field to the object at the same time... so the recNo field only exists in the application, not the database file itself... does that make any sense?...
Roel De Nijs

Joined: Jul 19, 2004
Posts: 8372

Hi Matthew,

First of all a warm welcome to the JavaRanch!

No worries, I'm quiet familiar with the database structure, so I know the record structure has no record number You could create a value object which holds the record number and the actual data of a contractor. That makes sense, but you always have to convert between this object and a String[] (because all your methods use a String[] in its signature). And I don't know if you will use String[] at the client or use a value object instead, but that would result in yet again a conversion between String[] and object.

Kind regards,
prakash bayas

Joined: Apr 09, 2011
Posts: 2
thank you,
roel, now assigning record number to a subcontractor record while looping!
roberto, i am doing fine!, just stumbling sometimes between interface provided in assignment and interface present in book,
matthew, can be done this way!,
I agree. Here's the link:
subject: field for record number in database file?
It's not a secret anymore!