User data persistence

Discussion in 'Java' started by Mike, Jul 11, 2005.

  1. Mike

    Mike Guest

    I am writing a Java application that uses about 1000 parameters in
    various calculations. All these parameters are displayed to the user in
    a JTable, and any can be modified. I would like to persist the user
    changes to these parameters, on the local machine. I'm new to Java, and
    am considering what the best options are for data persistence. It seems
    to me that, in this case, there are too many values to consider saving
    them using java.util.prefs.Preferences, and distributing a database
    with the app is probably overkill.

    I have previously written something similar using Microsoft VB.NET,
    where I created an XML file with some initial data, and distributed it
    with the application. The XML file was read into a DataSet, which was
    bound to DataGrid. If the user changed any values in the grid, the
    underlying DataSet was updated, and the XML file re-written to disk. Is
    it possible to do something similar in Java? I have looked at the
    Connection and ResultSet interfaces, but it does not appear that they
    can be used to read and write XML files.

    Mike.
     
    Mike, Jul 11, 2005
    #1
    1. Advertising

  2. Mike

    David Harper Guest

    Mike wrote:
    > I am writing a Java application that uses about 1000 parameters in
    > various calculations. All these parameters are displayed to the user in
    > a JTable, and any can be modified. I would like to persist the user
    > changes to these parameters, on the local machine. I'm new to Java, and
    > am considering what the best options are for data persistence. It seems
    > to me that, in this case, there are too many values to consider saving
    > them using java.util.prefs.Preferences, and distributing a database
    > with the app is probably overkill.
    >
    > I have previously written something similar using Microsoft VB.NET,
    > where I created an XML file with some initial data, and distributed it
    > with the application. The XML file was read into a DataSet, which was
    > bound to DataGrid. If the user changed any values in the grid, the
    > underlying DataSet was updated, and the XML file re-written to disk. Is
    > it possible to do something similar in Java? I have looked at the
    > Connection and ResultSet interfaces, but it does not appear that they
    > can be used to read and write XML files.


    You're right that a database is overkill.

    Even an XML file is over-complicating what is basically a simple
    problem. XML is useful when you need to store a complex hierarchical
    data structure, but you have a flat list of key/value pairs, and this
    argues strongly for a simpler solution.

    You should probably consider using a hash table to store the key-value
    pairs internally within your program. As such, java.util.Properties
    meets your needs better than java.util.prefs.Preferences because
    Properties is sub-classed from java.util.Hashtable with additional
    methods to read and write a text file of key-value pairs.

    David Harper
    Cambridge, England
     
    David Harper, Jul 11, 2005
    #2
    1. Advertising

  3. Mike

    Tom N Guest

    Mike wrote:

    > I am writing a Java application that uses about 1000 parameters in
    > various calculations. All these parameters are displayed to the user in
    > a JTable, and any can be modified. I would like to persist the user
    > changes to these parameters, on the local machine. I'm new to Java, and
    > am considering what the best options are for data persistence. It seems
    > to me that, in this case, there are too many values to consider saving
    > them using java.util.prefs.Preferences, and distributing a database
    > with the app is probably overkill.
    >
    > I have previously written something similar using Microsoft VB.NET,
    > where I created an XML file with some initial data, and distributed it
    > with the application. The XML file was read into a DataSet, which was
    > bound to DataGrid. If the user changed any values in the grid, the
    > underlying DataSet was updated, and the XML file re-written to disk. Is
    > it possible to do something similar in Java? I have looked at the
    > Connection and ResultSet interfaces, but it does not appear that they
    > can be used to read and write XML files.


    Have a look at java.beans.XMLEncoder
    and java.beans.XMLDecoder
     
    Tom N, Jul 11, 2005
    #3
  4. Mike

    Yamin Guest

    I'll second that one. XMLEncoder/Decoder makes persistence really
    really really easy. All the work has been done for you...no rewriting
    the wheel

    Encoder.write(any bean object)
    Object = Decoder.read();

    That's really it. You don't need to write anything fancy...no read
    method or write methods...you just make sure anythign you write is a
    java bean (all needed members have getter/setter,.default
    constructor....)

    File size can grow, but you have a fixed structure, so it should be
    fine.

    Yamin Bismilla
     
    Yamin, Jul 11, 2005
    #4
  5. Mike

    Virgil Green Guest

    Mike wrote:
    > I am writing a Java application that uses about 1000 parameters in
    > various calculations. All these parameters are displayed to the user
    > in a JTable, and any can be modified. I would like to persist the user
    > changes to these parameters, on the local machine. I'm new to Java,
    > and am considering what the best options are for data persistence. It
    > seems to me that, in this case, there are too many values to consider
    > saving them using java.util.prefs.Preferences, and distributing a
    > database with the app is probably overkill.
    >
    > I have previously written something similar using Microsoft VB.NET,
    > where I created an XML file with some initial data, and distributed it
    > with the application. The XML file was read into a DataSet, which was
    > bound to DataGrid. If the user changed any values in the grid, the
    > underlying DataSet was updated, and the XML file re-written to disk.
    > Is it possible to do something similar in Java? I have looked at the
    > Connection and ResultSet interfaces, but it does not appear that they
    > can be used to read and write XML files.
    >
    > Mike.


    I'm curious... Why do you think that a bloated (IMHO) XML file would be
    okay, but you think that the number of entries would be "too many" for a
    Preferences implementation? Note that I have not used the Preferences class.
    I'm merely curious. I do have a (possibly irrational) dislike for XML on
    principle which helps stoke this curiosity.

    Regardless... I'm thinking a Properties implementation would probably
    suffice... or a serialized HashTable.

    --
    Virgil
     
    Virgil Green, Jul 11, 2005
    #5
  6. Virgil Green wrote:
    > Mike wrote:
    >
    >>I am writing a Java application that uses about 1000 parameters in
    >>various calculations. All these parameters are displayed to the user
    >>in a JTable, and any can be modified. I would like to persist the user
    >>changes to these parameters, on the local machine. I'm new to Java,
    >>and am considering what the best options are for data persistence. It
    >>seems to me that, in this case, there are too many values to consider
    >>saving them using java.util.prefs.Preferences, and distributing a
    >>database with the app is probably overkill.
    >>
    >>I have previously written something similar using Microsoft VB.NET,
    >>where I created an XML file with some initial data, and distributed it
    >>with the application. The XML file was read into a DataSet, which was
    >>bound to DataGrid. If the user changed any values in the grid, the
    >>underlying DataSet was updated, and the XML file re-written to disk.
    >>Is it possible to do something similar in Java? I have looked at the
    >>Connection and ResultSet interfaces, but it does not appear that they
    >>can be used to read and write XML files.
    >>
    >>Mike.

    >
    >
    > I'm curious... Why do you think that a bloated (IMHO) XML file would be
    > okay, but you think that the number of entries would be "too many" for a
    > Preferences implementation? Note that I have not used the Preferences class.
    > I'm merely curious. I do have a (possibly irrational) dislike for XML on
    > principle which helps stoke this curiosity.


    You might not be pleased to know then that the Preferences API uses XML
    under the hood.

    >
    > Regardless... I'm thinking a Properties implementation would probably
    > suffice... or a serialized HashTable.
    >


    What I don't understand is why the original OP decided to use XML and
    then looked at the database interface code and concluded there was
    nothing to help him.

    Ray

    --
    XML is the programmer's duct tape.
     
    Raymond DeCampo, Jul 11, 2005
    #6
  7. Mike

    Roedy Green Guest

    On 10 Jul 2005 19:49:36 -0700, "Mike"
    <michael.o'> wrote or quoted :

    >I have previously written something similar using Microsoft VB.NET,
    >where I created an XML file with some initial data, and distributed it
    >with the application. The XML file was read into a DataSet, which was
    >bound to DataGrid. If the user changed any values in the grid, the
    >underlying DataSet was updated, and the XML file re-written to disk. Is
    >it possible to do something similar in Java? I have looked at the
    >Connection and ResultSet interfaces, but it does not appear that they
    >can be used to read and write XML files.
    >
    >Mike.


    Is it just a list or a complex tree of information?

    Possibilities:

    properties file http://mindprod.com/jgloss/properties.html
    a csv file http://mindprod.com/jgloss/csv.html
    a serialised file: http://mindprod.com/jgloss/serialization.html
    a one item per line text file.
    a DataOutputStream : http://mindprod.com/jgloss/fileio.html
    xml with custom parser : http://mindprod.com/jgloss/xml.html

    --
    Bush crime family lost/embezzled $3 trillion from Pentagon.
    Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
    http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

    Canadian Mind Products, Roedy Green.
    See http://mindprod.com/iraq.html photos of Bush's war crimes
     
    Roedy Green, Jul 12, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VHJldm9yIEFuZHJldw==?=

    3-Tier Web Application, forms authentication, persistence of user

    =?Utf-8?B?VHJldm9yIEFuZHJldw==?=, Dec 15, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,087
    =?Utf-8?B?VHJldm9yIEFuZHJldw==?=
    Dec 15, 2004
  2. Steve Mauldin
    Replies:
    7
    Views:
    513
    Steve Mauldin
    Jan 23, 2006
  3. Mosiuoa Tsietsi

    AudioInputStream byte data persistence

    Mosiuoa Tsietsi, Sep 15, 2003, in forum: Java
    Replies:
    0
    Views:
    429
    Mosiuoa Tsietsi
    Sep 15, 2003
  4. javaguy44
    Replies:
    10
    Views:
    1,011
    Michael Berg
    May 18, 2004
  5. Kenneth P. Turvey

    Java Persistence API and persistence.xml

    Kenneth P. Turvey, Mar 15, 2008, in forum: Java
    Replies:
    2
    Views:
    17,514
    Kenneth P. Turvey
    Mar 16, 2008
Loading...

Share This Page