This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to save object's state Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to save object Watch "How to save object New topic
Author

How to save object's state

Navneet Sharma
Greenhorn

Joined: Jan 02, 2013
Posts: 10
Hi Friends,

I am fetching business data from Oracle DB and saving it into a business class object. I want to save this object's state so I can use this anywhere in my code. I am thinking to achieve this with Seriailazation or with help of Session (session.setAttribute). Please suggest which will be most optimal and effective approach ? Please also suggest some others approaches if applicable ?

Thanks in advance !!
Mahender Parkipandla
Greenhorn

Joined: Dec 28, 2009
Posts: 17
Hi,
You can store it in Java Bean to access through out the application.
Get data from DB and store in Java Bean and store the Java Bean class in session.

You can get the data from session when ever you need.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
I am thinking to achieve this with Seriailazation or with help of Session (session.setAttribute). Please suggest which will be most optimal and effective approach ?


My suggestion - it depends on how long you need to keep the state around and on if the amount of memory used may be a problem.

I use serialization for objects that have a long useful life that may extend over several user sessions - you will need a mechanism for associating a unique file name with the user.

Sessions require less programming and are fine for objects that don't live past one user session.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to save object's state
 
Similar Threads
some help with student grade
Memento pattern in swing
The Serializable interface
XML Object serialization