File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 806

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: 806

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: 806

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: 806

Its okay Gregg, thank you.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

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