简体   繁体   中英

How to get multi table results of an stored procedure using SimpleJDBCCall in spring?

I'm implementing a Spring + MSSQL Server 2008 application. I use SimpleJDBCCall API to execute stored procedures and retrieve results.

For stored procedures with mono table results, it works fine, but I don't know how to use it for procedures with multi table results.

Sample procedure body:

multi table results

    SELECT * FROM TABLE1
    SELECT * FROM TABLE2

I was most ignorant, it does in fact work! You can specify both resultsets, with each its own mapper. In code it looks like this:

SimpleJdbcCall call = new SimpleJdbcCall(this.jdbc)
           .withProcedureName("get_users3")
           .returningResultSet("rs1", new ParameterizedRowMapper<Object[]>()
           {
              @Override
              public Object[] mapRow(ResultSet rs, int rowNum) throws SQLException
              {
                 return new Object[] { rowNum, rs.getInt(1), rs.getString(2) };
              }
           })
           .returningResultSet("rs2", new ParameterizedRowMapper<Object[]>()
           {
              @Override
              public Object[] mapRow(ResultSet rs, int rowNum) throws SQLException
              {
                 return new Object[] { rowNum, rs.getInt(1), rs.getString(2) };
              }
           });

  Map<String, Object> res = call.execute();
  assertNotNull(res.get("rs1"));
  assertNotNull(res.get("rs2"));
  List<Object[]> l1 = (List<Object[]>)res.get("rs1");
  List<Object[]> l2 = (List<Object[]>)res.get("rs2");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM