Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

multiple db statements in a jsp page  RSS feed

 
Peter Guillebaud
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In terms of performance is it better to use one sql statement object for many queries in a jsp page (and close it at the end of the page), or is it better to create and close a new statement object for each sql query?
TIA
 
Junilu Lacar
Sheriff
Posts: 10878
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMO, it's better to NOT have any db access on the JSP for any type of real-world development. Move the DB access code to a JavaBean.
If you must include db access code in your JSP, it might save you some time to use just one statement for all your queries. How much you save depends on just how costly it is to create a new Statement, which I unfortunately do not have any idea. I know that reusing a Connection will save you some time though since getting one can be really costly. Have you tried using a profiler?
Junilu
 
Peter Guillebaud
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Junilu. Why is it better to keep the db code out of the jsp? Is it smth to do with keeping the business logic separate from the presentation layer? Anyway, I will do as you suggest, many thanks.
 
Junilu Lacar
Sheriff
Posts: 10878
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, keeping business logic separated from presentation logic is the main reason.
Despite the ability to include Java scriplets in JSPs, you want to keep these down to a minimum. This makes it easier to maintain the page and keeps the JSP focused primarily on presentation. Using tag libraries helps keep the JSP scriplet-free because tags in effect "wrap" logic into an HTML-like element in your JSP. Taglibs are good, use them.
Conversely, you want to keep your beans / servlets relatively free of any type of presentation logic, especially the type of logic where you have
out.println("<B>This would be better as static text on the JSP<B>");
------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by JUNILU LACAR (edited November 08, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!