aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "JDBC Connection Pooling" Watch "JDBC Connection Pooling" New topic
Author

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) {
e.printStackTrace();
}
}

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) {
sqlException.printStackTrace();
}
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?

Regards,
Reema,
SCJP
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
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

These might help:

http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html

http://confluence.atlassian.com/display/DOC/Configuring+a+MySQL+Datasource+in+Tomcat


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

Joined: May 26, 2003
Posts: 30758
    
156

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

Agreed. Moving to our Tomcat forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Connection Pooling