• 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

Is it a Good way..

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Whenever we are dealing with Connection in JSP, can we put the connection in the session and use it through the session..
like:
Connection conn=DriverManager.getConnection(url,user,password);
session.putValue("conn",conn);
And in another page:
Connection conn=(Connection)session.getValue("conn");
So we need to create another connection rite..
Just taking it from session..
Is it recommended insteadof Connection Pooling..
Thanks in advance..
Pranit..
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pranit Saha:
Whenever we are dealing with Connection in JSP

Stop right there. You shouldn't be dealing directly with a Connection in a JSP. Even forgetting about maintainability issues, it's very hard to get right and not end up with connection or statement leaks if, for example, an impatient user presses STOP or REFRESH on the browser. Instead of this, consider using an MVC (Model II) architecture where the hard work is being done by controller command objects (action objects for Struts aficionados) and the JSPs merely render the results.

can we put the connection in the session and use it through the session..

First, this would consume one connection per user, something you can only afford in very low traffic situations. Second, session-scoped objects may be accessed by multiple threads simultaneously and Connection objects do not always take kindly to that, even disregarding that it would wreak havoc with any transactional stuff you might be doing.

Is it recommended insteadof Connection Pooling..

No. (You saw that one coming, right? )
- Peter
[ April 22, 2002: Message edited by: Peter den Haan ]
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks a lot for your reply.. It has helped me a lot..
Pranit..
 
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Peter.
For furthur reference check out "core patterns in J2EE" which explains different server side, client side layers in different scenarios.
Kishore.
 
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic