Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLyBird Database question

 
Rod Sinclair
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Just working on the URLyBird project. The database spec says that fields are null terminated if less than the maximum length. The database file I have is not like this though, it is padded with spaces where a field is less than the maximum length.

I am wondering how to write to the file because if I null terminate a field and start the next field after the null character this will make writing to the database quite tricky as all the other fields will have to move.

If we are allowed to pad the fields with spaces to their maximum length then this makes things alot easier, but the spec does not allow this as far as I can tell.

Just wondering how others have dealt with this.

Thanks in advance.

Rod
 
Mxolisi Veco
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day Rod.
I set each field to its maximum length before saving the record.

If the fields are not set to their maximum lengths, you will end up with records that do not have the same size. That means you will end up reading or writing to the wrong parts of the database and as a result you will end up with a corrupt database.

Each record must consist of fields that are set to the maximum length so that all the records will be the same length.
 
Roel De Nijs
Sheriff
Posts: 10400
133
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rod Sinclair wrote:Just wondering how others have dealt with this.

Did you use the search engine to look for other threads about your question?
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Rod. Welcome to JavaRanch!

Champion, it's just that this has been discussed a lot before around here, you know... try searching for an answer using the Search engine. I'm sure you'll find a lot of good points in the discussions that went on already!
 
Rod Sinclair
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok guys. Thanks for the responses. I'll check out the search engine.

Regards


Rod
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic