I disagree wholeheartedly with this practice for several reasons.

        First and foremost, the problem with passing the result set directly
to the JSP is that you must make sure to close your connections when done.
Your JSP might be able to close your result set, but your statement and
connection--as a best case scenario--have to wait for the GC.  Worst case
they stay out there and go stale, but they can still block active threads
from accessing the DB when you exceed your max connection count.

        Second, what happens if you encounter a SQLException while
processing the ResultSet?  Error handling is best done at the controller
level (when notified by the model, of course).  

        Third, and I've already said this, but processing results belongs in
the model.  Your view tier should not be your model.  This is the whole
premise of MVC--don't put your control or business logic in your view!

        Fourth, a ResultSet in itself is not Serializable, so you don't want
to try and pass it around, store it in the session, or any other silly thing
like that.

        So the Best Practice IMHO is to have a model component perform your
query, load the results into a generic list of DTO's.  It then becomes
trivial to display the content of the search results, page back and forth,
and so on.  It also maintains the integrity and separation of your MVC
design.  

David Hibbs
Staff Programmer / Analyst
Distributed Applications Development and Support
American National Insurance Company

> -----Original Message-----
> From: Gene Campbell [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, June 10, 2003 12:41 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Best practive for presenting a search result to a user
> 
> 
> If there is a Tag to deal with ResultSets, and you
> don't need to post process the data at all, you can
> use it in a jsp without needing to write any Java on
> the page.  It just becomes a DTO, that the controller
> hands to the view.  Right?
> 
> Best practice in my experience would be use the RS,
> and refactor if you need to.  But, you should not
> import java.sql in your jsps.  So, use a wrapper if
> you can't find an introspecting tag, or another trick.
> 
> - gene

> --  From Marc --
> Hello,
> 
> I would like to know what is for you the best practice
> to present to a user the result of a db query (a
> ResultSet variable)?
> 
> If, you can take some example of your suggestion, it
> will help me to understand...
> 
> thank you in advance
> 
> regards
> Marc
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
> http://calendar.yahoo.com
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to