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