Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > User data persistence

Reply
Thread Tools

User data persistence

 
 
Mike
Guest
Posts: n/a
 
      07-11-2005
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.

 
Reply With Quote
 
 
 
 
David Harper
Guest
Posts: n/a
 
      07-11-2005
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
 
Reply With Quote
 
 
 
 
Tom N
Guest
Posts: n/a
 
      07-11-2005
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
 
Reply With Quote
 
Yamin
Guest
Posts: n/a
 
      07-11-2005
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

 
Reply With Quote
 
Virgil Green
Guest
Posts: n/a
 
      07-11-2005
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


 
Reply With Quote
 
Raymond DeCampo
Guest
Posts: n/a
 
      07-11-2005
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.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-12-2005
On 10 Jul 2005 19:49:36 -0700, "Mike"
<michael.o'(E-Mail Removed)> 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/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Persistence API and persistence.xml Kenneth P. Turvey Java 2 03-16-2008 12:08 AM
Question about data persistence in Public variables Steve Mauldin ASP .Net 7 01-23-2006 07:46 PM
3-Tier Web Application, forms authentication, persistence of user =?Utf-8?B?VHJldm9yIEFuZHJldw==?= ASP .Net 4 12-15-2004 11:45 PM
EJB persistence versus Database persistence? javaguy44 Java 10 05-18-2004 07:08 PM
AudioInputStream byte data persistence Mosiuoa Tsietsi Java 0 09-15-2003 11:00 AM



Advertisments