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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 11
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: 39535
    
  27
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 - updated with new look and Ping home screen widget
Mario Schwaiger
Greenhorn

Joined: Jun 14, 2010
Posts: 11
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: 39535
    
  27
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: 11
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
 
Similar Threads
configuration of Bonecp class file
how to make a method in database access class for login
java.lang.NullPointerException at createStatement
Connection pooling with my own cofiguration file instead of Initial Context.
Connect MySql to Android