This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
hi, i have to save a jdbc-connection into a httpsession-object. if i do this in one servlet (save and restore) it works fine. if i do this with two servlets or http-requests the restore works not. what do i wrong ? i know it's not a fine way to do this, but i have to do it !
thanks a lot for help heiner [ November 28, 2002: Message edited by: heiner weilandt ]
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12267
1
posted
0
Storing a connection is a session is a REALLY BAD IDEA. No good can come of this for a huge variety of reasons. Why can't you use a connection pool? Bill
William is 100% correct (surprise surprise ) NO to putting the Connection on the session. As he said, there are soooo many reasons this is a bad thing, including the fact that it claims resources on the database that you aren't using and you can't close the Connection if the user never comes back. If Connection Pooling isn't an answer, even creating and discarding Connections when required is an inefficient but better solution. Dave
heiner weilandt
Ranch Hand
Joined: Sep 10, 2002
Posts: 46
posted
0
hi, yes, it' an bad idea. but i have to do this, because some of my bosses said, we have to realize commit-7rollback and logging over more than two http-request. i don't want to use ejb's ......
Kees van Oosterhout
Ranch Hand
Joined: Jul 08, 2002
Posts: 34
posted
0
No, no, no. !! A DBConnection should not be placed in the session object. Placing this in the context is definitly the way to go. The DBConnection will be accesible by all servlets in all requests. Off course the results returned from the connection can be placed in a session, wether or not in a self-defined data structure. Browse in the J2EE Api to find more information about the context, for a quick solution.
"...you've got to ask yourself one question, Do I feel lucky?"
R K Singh
Ranch Hand
Joined: Oct 15, 2001
Posts: 5369
posted
0
Originally posted by heiner weilandt: [QB][/QB]
Have you enabled session tracking ?? just curious . AW use getSession(false) in second servlet. [ November 29, 2002: Message edited by: Ravish Kumar ]
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12267
1
posted
0
yes, it' an bad idea. but i have to do this, because some of my bosses said, we have to realize commit-7rollback and logging over more than two http-request. i don't want to use ejb's ......
Why does that require that you save the connection? (I don't use JDBC much so I'm just curious!) Bill
What might be happening is: Your session is serialized, which JDBC Connections don't do so well. So when you try to retrieve it, the object is still there, but it's now "dead".