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