The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Database problem in URLyBird 1.2.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Professional Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "Database problem in URLyBird 1.2.1" Watch "Database problem in URLyBird 1.2.1" New topic
Author

Database problem in URLyBird 1.2.1

Xin Gang Sun
Greenhorn

Joined: Sep 03, 2009
Posts: 17
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?

This message was edited 1 time. Last update was at by Xin Gang Sun



Xin Gang Sun
boolean scjp_6 = true;
boolean scjd_URLyBird = willBeTrue();
//I hope!
Tahir Abbas
Ranch Hand

Joined: May 05, 2007
Posts: 44
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

Joined: Sep 03, 2009
Posts: 17
Thank you! Using RandomAccessFile make the code clear. I can just apply my mind to the concurrency.
Anne Crace
Ranch Hand

Joined: Aug 29, 2005
Posts: 223
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!


SCJP, SCJD
Georgiana Lungu
Ranch Hand

Joined: May 17, 2010
Posts: 34
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. " ?
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2114

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.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Georgiana Lungu
Ranch Hand

Joined: May 17, 2010
Posts: 34
OK, thank you for fast answer
 
 
subject: Database problem in URLyBird 1.2.1
 
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com