There are several class implementations for this purpose. The DataSourceUtils class is one of these classes. This is a convenient and powerful helper class that provides static methods to obtain connections from JNDI and close connections if necessary.