Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Throws EOFException during insertion in db file, and reading back data

 
conny pemfors
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After insertion of a record in contractor record database,
while reloading records from db file it throws EOFException. I wonder why it has this behaviour. something must be wrong with the data that was inserted in db file, but it used to work before...


/Conny



Nov 7, 2007 2:55:07 PM suncertify.db.Record getId
INFO: Returning id = 33
long input file: 6094
closing log printer and unlock recordNumbers
Nov 7, 2007 2:55:07 PM suncertify.db.RecordFileAccess getRecordList
FINE: found record 33
Nov 7, 2007 2:55:07 PM Record getId
FINER: ENTRY
Nov 7, 2007 2:55:07 PM suncertify.db.Record getId
INFO: Returning id = 33
Nov 7, 2007 2:55:07 PM RecordFileAccess readRow
FINER: ENTRY 6,094
Nov 7, 2007 2:55:07 PM closing log printer and unlock recordNumbers getRecordList
FINER: RETURN
java.io.EOFException
at java.io.RandomAccessFile.readFully(RandomAccessFile.java:373)
at java.io.RandomAccessFile.readFully(RandomAccessFile.java:351)
at suncertify.db.RecordFileAccess.readRow(RecordFileAccess.java:519)
at suncertify.db.RecordFileAccess.getRecordList(RecordFileAccess.java:387)
at suncertify.db.RecordFileAccess.<init>(RecordFileAccess.java:173)
at suncertify.db.Data.<init>(Data.java:76)
at suncertify.sockets.DBSocketRequest.<init>(DBSocketRequest.java:62)
at suncertify.sockets.RecordSocketServer.listenForConnections(RecordSocketServer.java:115)
at suncertify.sockets.RecordSocketServer.run(RecordSocketServer.java:90)
 
Anita S�rensen
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I to have the same problem. All reading and updating is successfull, all the data that I see in the database file is read and displayd, but I still get that EOFException.
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your insert method is not working correctly.
it is either writing less or more number of bytes than it should.
 
conny pemfors
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anita S�rensen:
I to have the same problem. All reading and updating is successfull, all the data that I see in the database file is read and displayd, but I still get that EOFException.



I solved the insertions with adding 1 to database.length(), where to write to file there must be one null byte before starting next writing to file.

database.seek(offset + 1);
database.write(out.toString().getBytes());


Conny
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Conny,

I am afraid that you are forgetting to write the delete flag which is one byte length.
Make sure that you calculate the file header (which I think you do since reading before insertion doesn't throw any exceptions).
Make sure that calculate the record length correctly (don't forget the delete flag), and make sure that you write bytes not text, use the example in the Monkhouse book it is really useful.

Hope that helps
 
conny pemfors
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Musab Al-Rawi:
Hi Conny,

I am afraid that you are forgetting to write the delete flag which is one byte length.
Make sure that you calculate the file header (which I think you do since reading before insertion doesn't throw any exceptions).
Make sure that calculate the record length correctly (don't forget the delete flag), and make sure that you write bytes not text, use the example in the Monkhouse book it is really useful.

Hope that helps


Hi Musab.

I know, I solved that problem and it worked perfectly afterwards, I just looked at the reading code where I add one.

Conny
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic