• 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

Database problem in URLyBird 1.2.1

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm fighting with the Data class. At first, I use DataInputStream & DataOutputStream object to access the data file.

All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.



But it has a lot of troubles such as updating the data file. I must delete the file and rebuild it frequently. It is not efficient.
Now I hava a new idea. Can I use the java.io.RandomAccessFile object according to Sun's requirement?
Or anyone has a better idea to implement it?
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also used java.io.RandomAccessFile to deal with the database. In database first there is information about database e.g; magic cookie value, number of fields etc then the record data in database starts. Data file section in instruction file will be very useful for dealing with database. If you search on this forum you'll get many useful threads regarding your problem.
 
Xin Gang Sun
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you! Using RandomAccessFile make the code clear. I can just apply my mind to the concurrency.
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I can just apply my mind to the concurrency.


Hello Xin,

I wouldn't worry about concurrency at this time. That is usually one of the last things you will do. Deal with reading the database first. You can use a synchronized block for your reads and writes but this is something that can easily be added later when you deal with locking. You need to do a little more than add a synchronized block to accomplish the locking, though! Lots of good information on this forum to help you with that when the time comes!
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have seen this post and is targeting one of my actual problems too. So, my question is, may I use RandomAccessFile although my specification states:
"All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII. " ?
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Georgiana Lungu wrote:So, my question is, may I use RandomAccessFile...



Oh yes, absolutely. If you look at the RandomAccessFile API, you can verify that it implements DataInput and DataOutput interfaces, so it can be used to deal with the database file.
 
Georgiana Lungu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, thank you for fast answer
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic