• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DB Processing Cost

 
Oliver Moore
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I need to return the following to my JSP page:
A list of results from a single table (to use in a select box)
A single result from the same table to display for editing.
In this scenario, the list I return will always contain the single result I wish to display. My question is, which is the most efficient way to get the single result. I see 3 alternatives:
1) Place the key for the single result in a response, Then iterate through the list at the JSP page until I find the desired single result.
2) go to the database twice, once to generate the list from a db access, then a 2nd db access to get the single result.
3) When processing the returned result set, pull out the desired single result and place it in a seperate bean to return to the page.
I think option 1 is the best, as 2 has 2 expensive DB accesses in it, and 3 would seem to make the class file processing the result very specific. Does this sound reasonable, or is there a better way altogether?
 
john smith
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right that 1 is the best of the three. You should always try to avoid the unecessary round trip involved in 2. 3 sounds like it is complicating things more than it needs to.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic