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

Database Problem in Bodgit & Scraper

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
problem is the Byte Array

Assuming the client wants to add some new fields to the database
Maybe the START OFFSET of file will be 140 or something. How will this offset be represented in 4 Byte Array? And how are we supposed to convert this offset into an integer?

Cos Now the Byte structure is like 0 0 0 70 so I easily take the last byte. If there are no changes to database schema structure ofcourse we don't ever have to read the first 3 bytes in a 4 byte field.

Also for length of a field all maximum lengths are < 127 (32,64 etc etc). So for a 2 byte field as mentioned in the assignment only last Byte is to be read. Is this an Assumption?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I believe that you are having this problem because you have not studied the API of the classes that you are using to perform i/o. Check the API for methods that can read from a file into Java's primitive types. You will need to read bytes into an array to form Strings, but for numeric data there are specific methods for that purpose.

Also, for the assignment, you do not have to consider that the client changes the structure of the file - just concentrate on reading from and writing to the existing file.
[ March 17, 2006: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I think in order to get a better score, you really have to create the db class that is capable of reading a different schema (w/ the same db structure).

If you are using RandomAccessFile, there are readByte(), readInt, readShort(), read(byte[]), pretty much everything is done for you, you will just need to specify the byte size to read depending on your schema you read from the header.
[ March 17, 2006: Message edited by: Ed Tse ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Originally posted by Ed Tse:
I think in order to get a better score, you really have to create the db class that is capable of reading a different schema (w/ the same db structure).

[ March 17, 2006: Message edited by: Ed Tse ]



You are correct Ed, but you don't haveto.

The problem for the original poster is caused by not having looked at the possibilities that Java offers for performing I/O.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Closing. Please continue in original thread on this subject.
    Bookmark Topic Watch Topic
  • New Topic