Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Database problem in URLyBird 1.2.1

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
OK, thank you for fast answer
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic