aspose file tools*
The moose likes Servlets and the fly likes SESSION vs Database trip Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "SESSION vs Database trip" Watch "SESSION vs Database trip" New topic
Author

SESSION vs Database trip

PANDU YELAMANCHILI
Greenhorn

Joined: Feb 02, 2001
Posts: 3
I have an application where I have to list 30 records per JSP page. There can be any number of records in the database.
Which of the methods is faster and consumes less resources?
-use session object to store all the records and the display them on the pages (30 at a time)
-go to the database for each page and get all records and display 30 per page
Any reply will be appreciated.
Thanks
Ashwin Desai
Ranch Hand

Joined: Jul 17, 2000
Posts: 124
Hi,
It is usually a compromise between a "faster" RESPONSE and "lesser" storage (read memory). You will not be able to have both of them at the same time.
Going to your question, it is better to go for Method 2) which reads the records off the database for every page since you do not know about the number of records in the database. This carries an overhead of a database access for every page access. But, you can work with limited memory (30 records)
Or you could read more than 30 records (say 5 * 30) and store them in the session object. Thus, you will be able to show 5 pages without a db access. Again, that number depends on your application and it's needs.
Hope this helps.
Ashwin.

Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
This is a topic which has been discussed here many times, so it may well be worth a few searches on past messages. You should find some quite detailed discussions and code samples both here and in the JDBC forum.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Revati Pathak
Greenhorn

Joined: Feb 19, 2001
Posts: 26
Originally posted by Frank Carver:
This is a topic which has been discussed here many times, so it may well be worth a few searches on past messages. You should find some quite detailed discussions and code samples both here and in the JDBC forum.

Revati Pathak
Greenhorn

Joined: Feb 19, 2001
Posts: 26
Frank InTheHouse
Greenhorn

Joined: Feb 19, 2001
Posts: 3
Check this out:
http://www.jspinsider.com/beans/snippets/database/HashTables.txt
Frank ;-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SESSION vs Database trip