Spring : jdbc 模板中的上一行

Spring : previous Line in jdbc template

我有这个要求:

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

我怎样才能解决这个问题以获得 resultSet

previous 元素

您不能在 ResultSet 上调用 prev()next(),因为它已为当前行预先初始化。

来自 mapRow() 的 Spring 文档:

Implementations must implement this method to map each row of data in the ResultSet. This method should not call next() on the ResultSet; it is only supposed to map values of the current row.

你应该做的是:

  1. 从你的 query() 中得到一个 ArrayList
  2. 迭代此列表并进行所需的比较。