Hello,

I am using Tomcat 7 built-in Connection Pool.
I followed the steps thats written in Tomcats website.
Apache Tomcat 7 (7.0.22) - JNDI Datasource HOW-TO

I got it working but, the question I want to ask is :
Should I have to declare:

Java Code:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource) envCtx.lookup("jdbc/social");
conn = ds.getConnection();
these steps in all pages (jsp, servlets)?

What if I create a class like:

Java Code:
public class ConnectionPool {

	public static Connection getConnection() {
		
		DataSource ds = null;
		Connection conn = null;
		
		try {
			Context initCtx = new InitialContext();
			Context envCtx = (Context) initCtx.lookup("java:comp/env");
			ds = (DataSource) envCtx.lookup("jdbc/social");
			conn = ds.getConnection();
			return conn;
			
		} catch (Exception e) {
			return null;
		} 

	}
}
and in my pages that need connections:

Connection conn = ConnectionPool.getConnection();

Is this feasible ? Or am I in the wrong way ?