This week's book giveaway is in the Agile/Processes forum.
We're giving away four copies of Building Green Software: A Sustainable Approach to Software Development and Operations and have Anne Currie, Sarah Hsu , Sara Bergman on-line!
See this thread for details.
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

The best way to deal with pooled JDBC-Connections in JSP

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I am working on a JSP-Project and sometimes I have to fetch or update the Database with JDBC. (I thought about using Hibernate but it would make more afford to use Hibernate for just some easy updates...).
So I bind my basic connection as a bean to the session:



Still I have some doubts whether I am doing everything in the right way (using Pooled Connections, Sessions...). Everything works fine so far, but I'm still unsure.
Thank you!



In the JSP-Files I use this connection in that way. Is there a possibility to check if the connection is really pooled?


 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a web app you should generally use pooled connections, and if possible the pool that is built into the servlet container (if there is one). For Tomcat this is described in http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html
 
Mario Schwaiger
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:In a web app you should generally use pooled connections, and if possible the pool that is built into the servlet container (if there is one).



Ok, I implemented it. Thank you for the information. So now, I should be able to use pooled connections?

Everything works as it should, just those doubts always...

By the way: Is it possible to implement this connection pool for Hibernate as well?





 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Hibernate can use that, although I can't point you in the right direction. But some directed searching for "hibernate tomcat connection pool" or some such phrase should lead you there.
 
Mario Schwaiger
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Works perfectly!

I checked out StackOverflow here:

http://stackoverflow.com/questions/5303671/configure-hibernate-to-connect-to-database-via-jndi-datasource

Even though, jpkrohling says it is necessary to use a persistence.xml, I'd say, it's not. For those, who have the same struggles as I had here's my new hibernate.cfg.xml. Everything works fine. Many thanks to Ulf for sharing his knowledge.

reply
    Bookmark Topic Watch Topic
  • New Topic