Results 1 to 5 of 5
  1. #1
    Ixnay is offline Member
    Join Date
    Jul 2007
    Posts
    1
    Rep Power
    0

    Exclamation Where to proceed now?

    Hi
    I have to create a database but not by using a JDBC by using textPad. It is going to be command line.I would like to know if i can store data,read,delete,search by using RandomAccess onto dat or txt files? for example: i have to delete an item by using the seek() then deleting it. Can this be possible?

    This database is like an inventory database storing materials like life-jackets and wakeboards for example. So i created a main class, then sub-classes. I have created my classes which use inheritance.

    Secondly, my program has a "address database" in it, which has the name, phone numbers and address of contacts.. Can i use a linked list to store data here?

    And no im not getting paid, and it is for personal achievement.. just incase your planning to give nasty replies.. Now that i have already created my classes, can someone tell me where to proceed now please
    Thanks

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    You can use a text file for this but it is difficult. You cannot just insert into the middle of a file, nor can you just delete. You will end up rewriting the entire file out again.

    You may find it easier to use a 100% Java DB embedded into your application like HSQLDB I've used it before and it is very easy.

    Good luck.

  3. #3
    levent Guest

    Default

    You can use a text file for this but it is difficult. You cannot just insert into the middle of a file, nor can you just delete. You will end up rewriting the entire file out again.
    I think this should be possible with random access files.

    You may find it easier to use a 100% Java DB embedded into your application like HSQLDB I've used it before and it is very easy.
    Latest version of JDK comes with a database which should simplify database developments. But i am not sure if JRE includes it too.

  4. #4
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Quote Originally Posted by levent View Post
    I think this should be possible with random access files.
    It is possible but difficult. For example lets say you have the following file of names:
    George Bush
    Kermit the Frog
    Bill Clinton
    Mike Young
    Skooby Doo

    Now you wish to delete Bill Clinton. The name "Bill Clinton" takes up 12 bytes right in the middle of the file. You cannot just remove them like in an editor. You can blank them out but, in order to remove them you must rewrite the file from at least the beginning of Bill Clinton to the end.

    For a small database you can read the entire thing into memory and write it back out when you have finished manipulating it.

    Or you can use fixed length records in the file so that every name takes up 20 bytes (or whatever). This will still leave holes in the middle of the file that you have to keep track of and fill back in when inserting data.

    The only two viable choices are to read the whole lot into a memory structure and write it out when done or to use a real database such as hsqldb (I advocate hsqldb because I've used it and it is delightfully easy).

  5. #5
    levent Guest

    Default

    The only two viable choices are to read the whole lot into a memory structure and write it out when done or to use a real database such as hsqldb (I advocate hsqldb because I've used it and it is delightfully easy).
    I agree to this comment. These are the best approaches for this problem.

    There are databases which does not require a database server. The databases are kept as plain files in your file system and as far as i know you can reach them with JDBC.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •