aspose file tools*
The moose likes Servlets and the fly likes storing data without using a database.   Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "storing data without using a database.   " Watch "storing data without using a database.   " New topic
Author

storing data without using a database.

Saurabh Agarwal
Greenhorn

Joined: Aug 27, 2007
Posts: 18
Sir/mam

I have to take data from a form and then store that data without using a database.
now, again when user inserts next record...same servlet is called which stored earlier record....so the problem is how can i persist previous record and store next record in servlet because every time the servlet is called whole record previously stores is refreshed.

I dont hav to use a database....
Do i need to use sessions here...so that it can persist data on same servlet calls.....

tx in advace...
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Hi,

Welcome to JavaRanch!

You may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Funny "handles" aren't acceptable here. You can change your display name here. Thanks!

As to your question, i do not think its very clear.
You want to store the data on a physical storage? I am asking this because you mentioned that you can use session.
What is the data that is to be stored? What are the operations that you will do on the data i.e read only, read + modify.


apigee, a better way to API!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
I have to take data from a form and then store that data without using a database.


The simplest way to provide storage of data that lasts longer than a user session and survives when the server is off is to use Java object serialization to a file. It is up to the programmer to come up with a naming and location convention for the file.

You might use a custom Java object or just use one of the collection classes. See the java.io package JavaDocs for ObjectOutputStream and ObjectInputStream. Once you have a naming and locating convention in place, the rest is pretty simple.

Bill


Java Resources at www.wbrogden.com
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

The simplest way to provide storage of data that lasts longer than a user session and survives when the server is off is to use Java object serialization to a file.


Yeah thats correct, but it comes with problems that arise due to the class version changes. Your application, if required, must be capable of handling the same.
Other way could be to serialize it as an xml file, so that it can be read by programs written in languages other than java. Also, it will be easy to migrate these to a new scheme if class/data definition changes. It all depends on the requirement that you have.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
You may want to store the data in a simple text file as well as name value pairs.

But it again depends on the kind of data that you want to store and importance of that data , any anticipated changes to the data storage method.


Rahul Bhattacharjee
LinkedIn - Blog
Amit Kumargupta
Ranch Hand

Joined: Apr 13, 2007
Posts: 54
Its depends on the what kind of data you storing....
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
My answer, use a database!!! If you don't have one configured for you, utilize something like Derby in the embedded mode. This will store your data to the file system for you and allow the easy capability of growing your application easily when the time comes.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
I agree with William Brogden. You may store your data to a Vector in your Servlet and at appropriate time save that Vector (persist data) periodically.

I can help you further if your want!

Maki Java
[ September 25, 2007: Message edited by: Maki Jav ]

Help gets you when you need it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing data without using a database.
 
Similar Threads
I need suggestion on Servlet's init()
Parsing attributes across webapps
servlet instance question
Application-Managed Transaction without joining
When do ejb 3 entity bean get/set methods get called