我正在尝试从转换ResultSet
为CachedRowSet/CachedRowSetImpl
. 在ResultSet
填充方法之后似乎是空的,但CachedRowSet
. 我一直在到处寻找,尝试不同的方法(包括工厂)。下面是一个代码片段,其中包含一些关于正在发生的事情的迹象。
class ResultSetMapper implements RowMapper<CachedRowSet>{
@Override
public CachedRowSet map(ResultSet rs, StatementContext ctx) throws SQLException {
//CachedRowSet crs = RowSetProvider.newFactory().createCachedRowSet();
System.out.println(rs.getLong("something")); -> This gets printed
CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(rs);
System.out.println(crs.getInt("something"); -> ArrayIndexOutOfBoundsException (mostly -1, sometimes returning 0)
System.out.println(rs.getLong("something")); -> This doesn't get printed
System.out.println(crs.size()); -> 0
return crs;
}
}
对此问题的任何帮助或见解将不胜感激!
编辑:通过一些调试,我发现 CachedRowSet is not empty。RowSetMD.colCount = 3。它也有正确的标签。这不会改变问题,但可以确保我不会在空对象上调用 getter。这使得问题更难掌握