简体   繁体   中英

How to get results of an stored procedure using SimpleJDBCCall in spring with two result table?

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. here is the screenshot from query of my database that returns two result table. 1

here is the code that i use,this code work properly with single table result`

public class LoadOnDemandSP extends StoredProcedure{
    private static final String SPROC_NAME = "sps_IME_EF_GetAllMarketData";

    public LoadOnDemandSP(DataSource ds) {
        super(ds, SPROC_NAME);

        RowMapper mapper = new MyRowMapper();
        declareParameter(new SqlReturnResultSet("Return Value", mapper));
        declareParameter(new SqlParameter("FromDate", Types.VARCHAR));
        declareParameter(new SqlParameter("ToDate",Types.VARCHAR));
        compile();

    }

    public List execute(String FromDate,String ToDate) {
        Map inputs = new HashMap();
        inputs.put("FromDate",FromDate);
        inputs.put("ToDate",ToDate);
        Map map = super.execute(inputs);
        if (map != null && map.size() > 0) {
            return (List) map.get("Return Value");
        } else {
            return new ArrayList();
        }


    }


    private class MyRowMapper implements RowMapper<LoadOnDemand> {
        public LoadOnDemand mapRow(ResultSet rs, int rowNum) throws SQLException {
            LoadOnDemand l = new LoadOnDemand();
//              f.setDay(rs.getInt("ContractDay"));
            l.setInternalQuantity(rs.getInt("DVaznTon"));
            l.setExportalQuantitiy(rs.getInt("SVaznTon"));
            l.setInternalValue(rs.getDouble("DArzeshMillion"));
            l.setExternalValue(rs.getDouble("SArzeshMillion"));
            l.setInternalBuyersCount(rs.getInt("DBuyers"));
            l.setExternalBuyersCount(rs.getInt("SBuyers"));
            l.setInternalSellersCount(rs.getInt("DSellers"));
            l.setExternalSellersCount(rs.getInt("SSellers"));
            l.setInternalGoodsCount(rs.getInt("DSymbols"));
            l.setExternalGoodsCount(rs.getInt("SSymbols"));
            l.setTablo(rs.getString("GrouhAsli"));
            return l;
        }
    }



}

///Added////

My sample SP:

CREATE PROCEDURE [dbo].[sps_Test1]

WITH RECOMPILE      
AS

SELECT *

FROM dbo.tbl1

SELECT *

FROM dbo.tbl2

You could not handle the multiple tables. you can join the two tables as one by using either union or unionAll

CREATE PROCEDURE [dbo].[sps_Test1]

WITH RECOMPILE      
AS

SELECT *

FROM dbo.tbl1
UNION
SELECT *

FROM dbo.tbl2

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