wood burning stoves 2.0
The moose likes Tomcat and the fly likes JDBC Connection Pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "JDBC Connection Pooling" Watch "JDBC Connection Pooling" New topic

JDBC Connection Pooling

Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Hi, I have sufficient experience in Java EE except the EJB part where the heavy weight app servers comes into action. I have made a couple of web apps nd deployed (WAR) on Tomcat. WHat I want 2 do is make a JDBC Connection pool, I browsed through a gud no. of articles but couldn't get it. Following is a code snippet frm JavaRanch journal, the code looks fine but it doesn't explain as how 2 configure it (web.xml-DD entries) on Tomcat:
public void init(ServletConfig config) throws ServletException {
try {
// Look up the JNDI data source only once at init time
Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
datasource = (DataSource) envCtx.lookup("jdbc/MyDataSource");
catch (NamingException e) {

private Connection getConnection() throws SQLException {
return datasource.getConnection();

public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException {
Connection connection=null;
try {
connection = getConnection();
..<do JDBC work>..
catch (SQLException sqlException) {
finally {
if (connection != null)
try {connection.close();} catch (SQLException e) {}

Can anybody help me in this regard. I'm using MySQL and Tomcat 5. How can I run the above mentioned code snippet?

Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
This seems like more of Tomcat configuration issue than a JDBC question.
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

These might help:



[My Blog] [JavaRanch Journal]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32844

Originally posted by Maximilian Stocker:
This seems like more of Tomcat configuration issue than a JDBC question.

Agreed. Moving to our Tomcat forum.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link: http://aspose.com/file-tools
subject: JDBC Connection Pooling
It's not a secret anymore!