wood burning stoves 2.0*
The moose likes Servlets and the fly likes How to get a connection from the connection pool in a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get a connection from the connection pool in a servlet" Watch "How to get a connection from the connection pool in a servlet" New topic
Author

How to get a connection from the connection pool in a servlet

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Hi everybody, I am stuck in middle of an application. I am using connection pooling to connect to the database.

This is the context.xml file under META-INF which is responsible to maintain the connection pool.

Now I want to use a connection from this pool in a servlet. How can I do this.

Thank you all in advance.


Love all, trust a few, do wrong to none.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Using a jsp I am retrieving the data,

but I have to shift this into a MVC architecture. To do so, I need the connection in the servlet. How can I get a connection from the pool in a servlet?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

It will be something like this...



BTW, this code was taken directly from the Tomcat docs.


GenRocket - Experts at Building Test Data
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Gregg Bolinger wrote:It will be something like this...



BTW, this code was taken directly from the Tomcat docs.


Thanks Gregg, for the quick reply, can you help me more? How can I get the connection object from DataSource and can you please explain what is


Thank you in advance.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I tried to be subtle with my hint to the Tomcat docs. Here is something more obvious. These are easily answered with some simple Google searches and looking at the API. Please try to find some information before asking very common questions.

http://java.sun.com/javase/6/docs/api/javax/sql/DataSource.html
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

This is also not JSP related so moving...
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Its okay Gregg, thank you.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Thanks a lot Gregg. The code is working now.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

anusha chaitanya wrote:Thanks a lot Gregg. The code is working now.


Awesome! Glad to hear it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get a connection from the connection pool in a servlet
 
Similar Threads
Problem in implementing connection pooling in tomcat6.0
javax.naming.NamingException: Could not dereference object
Context and WAR file
Connection pooling using Tomcat
Help With Connection Pool