Kerry Friesen<br />SCJP 1.2<br />SCJD
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I think your question was the opposite of Phil's answer: you are trying to find out what the record number is.
Originally posted by Philippe Maquet:
Maybe you're right, but IMO, at the db level, we explained exactly the same stuff.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Kerry Friesen<br />SCJP 1.2<br />SCJD
But I do need something to argue with you about since I seem to be loosing in that other thread
If a client asks you to read record number 5, you know that you can go to the start of the file, skip the header and schema, then skip 4 records, and you must be at record number 5.
Regards, Richard
Originally posted by Richard Jackson:
Would you mind that I enjoy your discussion?
Originally posted by Richard Jackson:
When we wanna read record,we should skip required bytes ,and I image the code like [that shown above]
Originally posted by Richard Jackson:
But I still have a question according this following,
In the method,does the argument 'recNo' imply that it's 'record number' or 'record count'?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Regards, Richard
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
you would be better to have constants in your class with the same values.
you could just read the header and schema (you have to do that anyway), then use RandomAccessFile's getFilePointer() method to tell you where you currently are in the file.
Instead of doing a seek() to the start of the file, then skipBytes to the start of the data, why not seek() directly to the start of the data?
In which case you probably want to only perform one skip directly to the required record, rather than multiple little skips.
You need to read the deleted flag before you start reading fields. There is only one deleted flag, not one per field.
This means that your handling of the deleted flag status must move as well. You want to skip reading the individual fields if the entire record has been deleted.
You are missing code in the case where the record has been deleted - you will have to skip over the current record.
Actually I just realised - the code within your loop will read entire records, however the loop itself will only work for the number of fields in the record. So your counters inside the for() statement are incorrect.
Regards, Richard
Andrew:
you could just read the header and schema (you have to do that anyway), then use RandomAccessFile's getFilePointer() method to tell you where you currently are in the file.
Richard:
I agree.
Andrew:
Instead of doing a seek() to the start of the file, then skipBytes to the start of the data, why not seek() directly to the start of the data?
Richard:
You mean that I should seek the header of current record directly?
But I am confused this.Should I give up using 'seek()' method?
RichardActually you mean that we need skip bytes with changeable length so as to read any record.OK?
Richard
In fact,my counters is NOT correct.
How can I do to decide the loop counter?
Richard:
Each record contains some bytes,thus many people use ByteArray or CharArray .Are they required?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
You could have:
calculate header + schema + (record size * number of records)
seek(calculated bytes)
Regards, Richard
How to do to get String array of record?
Paul F. Williams<br />SCJP July 2003
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
Paul - does you assignment require some sort of lock() method? At what point in the above scenario would this be called? Is there a way you can write the client code to use locking to ensure that the record it updates is the same one it has read?
Paul F. Williams<br />SCJP July 2003
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|