posted 16 years ago
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 ]