Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S DB Interface read( int recNo)?

 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The db interface that must be implemented has a read( int recNo ) method. If using the DataInputStream, how can one implement this read method if only one method expects an int the skipBytes. I can't see the benefit of using this method nor does it seems to assist in reading the file? So, what is the intention of the "int"?

Since I'm completely confused, I hope I've stated my question clearly enough so that I'm not confusing anyone else.

Thanks in advance for your help!
 
Manik Saha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why dont u use RandomAccessFile instead ? For the skipBytes part, you may want to save it the first time you parse the file and then subsequently use it to access the records.

recordposition = (recordNo*sizeOfARecord) + skipBytes;

assuming recordNo 0 is the first record..
 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manik,
In the B&S document, it states the following:

Data file format section
All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream.

You stated:
For the skipBytes part, you may want to save it
the first time you parse the file and then
subsequently use it to access the records.

I'm not sure what you mean by "save it"?
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Since I'm completely confused, I hope I've stated my question clearly enough so that I'm not confusing anyone else.


Not me. I went through this once.


...skipBytes. I can't see the benefit of using this method nor does it seems to assist in reading the file?

Skip bytes cannot replace the seek function with RandonmAccessFile. See that skipbytes only makes an attempt to skip. Here is the javadoc for it

Makes an attempt to skip over n bytes of data from the input stream, discarding the skipped bytes. However, it may skip over some smaller number of bytes, possibly zero. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. This method never throws an EOFException. The actual number of bytes skipped is returned.



So, what is the intention of the "int"?

Don't caught you question clearly. The int recNo is to specify the record you like to pull from database. 1 (or 0)means first record 2 (or 1) means second record.

I think you might have already figured out. If not take a look at the following url's.


http://www.coderanch.com/t/186390/java-developer-SCJD/certification/RandomAccessFile

http://www.coderanch.com/t/186352/java-developer-SCJD/certification/urlyBird-requirement-clarification

http://www.coderanch.com/t/186351/java-developer-SCJD/certification/db-access-returning-String


[ November 01, 2004: Message edited by: jiju ka ]
[ November 01, 2004: Message edited by: jiju ka ]
 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi JiJu,
Ahhhh, now I follow. Thanks for your help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic