Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SESSION vs Database trip

 
PANDU YELAMANCHILI
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Frank InTheHouse
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this out:
http://www.jspinsider.com/beans/snippets/database/HashTables.txt
Frank ;-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic