我有这个要求:
private List<IWsResponse> getBPartnerDetails(String valueNetwork, String reportLevel2) {
JdbcTemplate tm = new JdbcTemplate(ds.getDataSource());
StringBuffer sql = new StringBuffer("SELECT * FROM XRV_BPARTNERDETAILS where rownum < 10 order by BPartner_ID");
response = tm.query(sql.toString(), new BPartnerMapper());
return response;
}
在BPartnerMapper
中,我想执行以下操作:
获取ResultSet中的前一个元素,将其与实际行
进行比较@Override
public IWsResponse mapRow(ResultSet rs, int rowNum) throws SQLException {
rs.previous();
int prev_Bpartner_ID = rs.getInt("BPARTNER_ID");
int prev_Location_ID = rs.getInt("BPARTNER_LOCATION_ID");
int prev_User_ID = rs.getInt("User_ID");
rs.next();
int Bpartner_ID = rs.getInt("BPARTNER_ID");
int Location_ID = rs.getInt("BPARTNER_LOCATION_ID");
int User_ID = rs.getInt("User_ID");
// My code
}
我在rs.previous()
中收到错误:
java.sql.SQLException: Invalid operation for forward only resultset : previous
如何解决此问题以获取previous
resultSet
元素
答案 0 :(得分:0)
您无法在ResultSet上调用prev()
或next()
,因为它已为当前行预先初始化。
来自mapRow()
的春季文档:
实现必须实现此方法以映射ResultSet中的每一行数据。此方法不应调用ResultSet上的next();它只应映射当前行的值。
你应该做的是:
ArrayList
query()