The Specification says that we should create the connection pool in the ServletContextListener. I have the code for creating a connection pool (see below). How do I create it in the ServletContextListener?
import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class DBConnection
{
public static Connection getDBConnection() throws SQLException
{
Connection conn = null;
try
{
InitialContext ctx = new InitialContext();
DataSource ds = ( DataSource ) ctx.lookup( "java:comp/env/jdbc/MySQLDB" );
try
{
conn = ds.getConnection();
}
catch( SQLException e )
{
System.out.println( "Open connection failure: " + e.getMessage() );
}
}
catch( NamingException nEx )
{
nEx.printStackTrace();
}
return conn;
}
}