0

我正在实现一个 Spring+ MSSQL Server 2008 应用程序。我使用 SimpleJDBCCall API 来执行存储过程和检索结果。

对于具有单表结果的存储过程,它工作正常,但我不知道如何将它用于具有多表结果的过程。这是我的数据库查询的屏幕截图,它返回两个结果表。1

这是我使用的代码,此代码适用于单表结果`

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;
        }
    }



}

///添加////

我的示例 SP:

CREATE PROCEDURE [dbo].[sps_Test1]

WITH RECOMPILE      
AS

SELECT *

FROM dbo.tbl1

SELECT *

FROM dbo.tbl2
4

1 回答 1

0

您无法处理多个表。您可以使用union或将两个表合并为一个unionAll

CREATE PROCEDURE [dbo].[sps_Test1]

WITH RECOMPILE      
AS

SELECT *

FROM dbo.tbl1
UNION
SELECT *

FROM dbo.tbl2
于 2013-04-08T12:10:37.887 回答