• 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

store Connection in HttpSession ?

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ......
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Bring out your dead! Or a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic