You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ryan Cornia <rc...@dced.state.ut.us> on 2001/09/05 16:06:55 UTC

CachedRowSet or SQL, what is the best way?

Is anyone using the early access of CachedRowSet for data access, or are people just using straight JDBC calls?

I've been using straight JDBC calls, but it looks like CachedRowSet would be easier. Anyone know when it will be officially released? Is it currently stable?

Thanks,
Ryan



Re: CachedRowSet or SQL, what is the best way?

Posted by Gregor Rayman <gr...@gmx.net>.
"Ryan Cornia" <rc...@dced.state.ut.us> asks:



> Is anyone using the early access of CachedRowSet 
> for data access, or are people just using straight 
> JDBC calls?
> 
> I've been using straight JDBC calls, but it looks 
> like CachedRowSet would be easier. Anyone know when
> it will be officially released? Is it currently stable?

I use cached RowSets beacuse they hide the connections,
SQL and the whole persistence stuff from the JSP which
uses them.

I only had problems with some Oracle specialities (nested
ResultSets will not be serialized by the EarlyAccess 
version).

Other option would be to use the Rowset which opens a life
connection to the datasource. The Action would set up its
properties and the RowSet would fetsch the data when needed
in the JSP. The JSP has then to be responsible for closing
teh RowSet (I always call rs.close() in the JSP, even though
for the cached ones it is not necessary and it means I have 
to have scriplet in my JSP)

I'd prefer the second option if the caching becomes too heavy
burden for the memory. (Like a JSP which returns a table with
one million rows)

--
gR



Re: CachedRowSet or SQL, what is the best way?

Posted by Ted Husted <hu...@apache.org>.
CachedRowSet seems fine for read-only accesses, but I'm told that
inserts and updates can be flakey (or impossible) with some drivers.

I have used RowSets extensively for accesses, and never had a problem.
The Jakarta TagLibs dbTag has also been recently extended so that you
can use read-only RowSets with their ResultSet tag (which has some nice
formatting features). 

Personally, I've gone back to ArrayLists and use a
BeanUtils.Populate-like method to quickly move the ResultSet into a
collection of beans. The nice thing here is that it's easier to extend
your own bean with custom accessors to format the property in various
ways, and provide other business logic hooks. Standardizing on
collections also makes it easier to move prototype code directly into
production, since they are easy to manufacture.

// Transfer ResultSet to Collection of target beans **
if (resultSet!=null) {
        collection = ResultSetUtils.getCollection(
                target,resultSet);
}

Where ResultSetUtils does this 

    public static void populate(Object bean,
                                ResultSet resultSet)
        throws SQLException {
        // Build a list of relevant column properties from this
resultSet
        HashMap properties = new HashMap();
        // Acquire resultSet MetaData
        ResultSetMetaData metaData = resultSet.getMetaData();
        int cols = metaData.getColumnCount();
        // Scroll to next record and pump into hashmap
        if (resultSet.next()) for (int i=1; i<=cols ; i++) {
            // :TODO: Let native types through
            /*
            int type = metaData.getType(i);
            if ...
            properties.put(metaData.getColumnName(i),
                resultSet.getObject(i));
            else
            */
            properties.put(metaData.getColumnName(i),
                resultSet.getString(i));
        }
        // Set the corresponding properties of our bean
        try {
            BeanUtils.populate(bean, properties);
        } catch (Exception e) {
            throw new SQLException("BeanUtils.populate threw " +
e.toString());
        }
    }


-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/about/struts/


Ryan Cornia wrote:
> 
> Is anyone using the early access of CachedRowSet for data access, or are people just using straight JDBC calls?
> 
> I've been using straight JDBC calls, but it looks like CachedRowSet would be easier. Anyone know when it will be officially released? Is it currently stable?
> 
> Thanks,
> Ryan