• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DB Processing Cost

 
Oliver Moore
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic