Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will be something like this...



BTW, this code was taken directly from the Tomcat docs.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is also not JSP related so moving...
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its okay Gregg, thank you.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Gregg. The code is working now.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anusha chaitanya wrote:Thanks a lot Gregg. The code is working now.


Awesome! Glad to hear it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic