Here you can find the source of getConnection(CommonDataSource dataSource)
public static Connection getConnection(CommonDataSource dataSource) throws SQLException
//package com.java2s; //License from project: Apache License import java.sql.Connection; import java.sql.SQLException; import javax.sql.CommonDataSource; import javax.sql.ConnectionPoolDataSource; import javax.sql.DataSource; import javax.sql.XADataSource; public class Main { public static Connection getConnection(CommonDataSource dataSource) throws SQLException { Connection connection = null; if (dataSource != null) { if (dataSource instanceof ConnectionPoolDataSource) { connection = ((ConnectionPoolDataSource) dataSource).getPooledConnection().getConnection(); } else if (dataSource instanceof DataSource) { connection = ((DataSource) dataSource).getConnection(); } else if (dataSource instanceof XADataSource) { connection = ((XADataSource) dataSource).getXAConnection().getConnection(); }/*from w ww . j a v a 2s . co m*/ } return connection; } public static Connection getConnection(CommonDataSource dataSource, String userName, String password) throws SQLException { Connection connection = null; if (dataSource != null) { if (dataSource instanceof ConnectionPoolDataSource) { connection = ((ConnectionPoolDataSource) dataSource).getPooledConnection(userName, password) .getConnection(); } else if (dataSource instanceof DataSource) { connection = ((DataSource) dataSource).getConnection(userName, password); } else if (dataSource instanceof XADataSource) { connection = ((XADataSource) dataSource).getXAConnection(userName, password).getConnection(); } } return connection; } }