public Connection connect(RowSetInternal caller) throws SQLException {

        // Get a JDBC connection.
        if (caller.getConnection() != null) {
            // A connection was passed to execute(), so use it.
            // As we are using a connection the user gave us we
            // won't close it.
            userCon = true;
            return caller.getConnection();
        }
        else if (((RowSet)caller).getDataSourceName() != null) {
            // Connect using JNDI.
            try {
                Context ctx = new InitialContext();
                DataSource ds = (DataSource)ctx.lookup
                    (((RowSet)caller).getDataSourceName());

                // Check for username, password,
                // if it exists try getting a Connection handle through them
                // else try without these
                // else throw SQLException

                if(((RowSet)caller).getUsername() != null) {
                     return ds.getConnection(((RowSet)caller).getUsername(),
                                            ((RowSet)caller).getPassword());
                } else {
                     return ds.getConnection();
                }
            }
            catch (NamingException ex) {
                SQLException sqlEx = new SQLException(resBundle.handleGetObject("crsreader.connect").toString());
                sqlEx.initCause(ex);
                throw sqlEx;
            }
        } else if (((RowSet)caller).getUrl() != null) {
            // Connect using the driver manager.
            return DriverManager.getConnection(((RowSet)caller).getUrl(),
                                               ((RowSet)caller).getUsername(),
                                               ((RowSet)caller).getPassword());
        }
        else {
            return null;
        }
    }
Establishes a connection with the data source for the given
<code>RowSet</code> object.  If the rowset's <code>dataSourceName</code>
property has been set, this method uses the JNDI API to retrieve the
<code>DataSource</code> object that it can use to make the connection.
If the url, username, and password properties have been set, this
method uses the <code>DriverManager.getConnection</code> method to
make the connection.
<P>
This method is used internally by the reader and writer associated with
the calling <code>RowSet</code> object; an application never calls it
directly.

@param caller a <code>RowSet</code> object that has implemented
              the <code>RowSetInternal</code> interface and had
              this <code>CachedRowSetReader</code> object set as
              its reader
@return a <code>Connection</code> object that represents a connection
        to the caller's data source
@throws SQLException if an access error occurs
src/main/java/org/replicadb/rowset/sun/rowset/internal/CachedRowSetReader.java