• 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

putting statemet into session

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am using normal jdbc statements (no stored procedures or precompiled SQL statements) and putting Statement object in session.instead of putting database connection codes in each page .

should I get some performance issue in my web application if i do that?
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Umesh,
Welcome to javaranch.

Firstly, database interaction in jsps(if you are using those) is not recommended. There should be a clean separation between the view layer and the model.
However, if you have to do that, i would suggest, not to do the above, probably because of the following:
1) A statement is not supposed to be executed concurrently by two threads. So, if the user opens two windows (popup/using ctrl-N), the two will share the session and hence there is a chance that the statement will be executed concurrently by two threads. (QA will do this for sure ;) )
2) When will you close the statement? This will be a problem as you may have a heavy load on your application and every user will have a different statement that will not be closed for a long time.

If the intent is to avoid copy paste of the statement creation code in all pages, i would suggest you to use a utility class.
Also, you can use a connection pool(if you are not already using it) to reduce the connection creation time.
[ May 03, 2007: Message edited by: Nitesh Kant ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic