Code example for DataSource

Methods: getConnection

0
    protected Connection getConnection(String dataSourceName) throws SQLException, NamingException {
        DataSource dataSource = this.getDataSource(dataSourceName);
        if (dataSource == null) {
            return null; 
        } 
        return dataSource.getConnection();
    } 
 
    protected int executeUpdate(String dataSourceName, String sql, Map<Integer, Object> params) throws SQLException, NamingException {
        Connection conn = this.getConnection(dataSourceName);
        if (conn == null) {
            throw new SQLException(); 
        } 
        PreparedStatement stmt = null;
        try { 
            stmt = conn.prepareStatement(sql);
            if (params != null) {
                for (Integer index : params.keySet()) {
                    stmt.setObject(index, params.get(index));
                } 
            }