• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

B&S DB Interface read( int recNo)?

 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"?
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


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

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

https://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: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi JiJu,
Ahhhh, now I follow. Thanks for your help!
 
reply
    Bookmark Topic Watch Topic
  • New Topic