• Post Reply Bookmark Topic Watch Topic
  • New Topic

putting statemet into session  RSS feed

 
Umesh Gupta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!