Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mario Schwaiger
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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?


 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 16
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • 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: 16
  • Mark post as helpful
  • send pies
  • 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic