• Post Reply Bookmark Topic Watch Topic
  • New Topic

store Connection in HttpSession ?

 
heiner weilandt
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
R K Singh
Ranch Hand
Posts: 5388
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!