File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes The best way to deal with pooled JDBC-Connections in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "The best way to deal with pooled JDBC-Connections in JSP" Watch "The best way to deal with pooled JDBC-Connections in JSP" New topic
Author

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

Mario Schwaiger
Greenhorn

Joined: Jun 14, 2010
Posts: 14
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
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
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


Ping & DNS - my free Android networking tools app
Mario Schwaiger
Greenhorn

Joined: Jun 14, 2010
Posts: 14
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
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
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

Joined: Jun 14, 2010
Posts: 14
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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The best way to deal with pooled JDBC-Connections in JSP