简体   繁体   中英

Stored Procedure with 3 select statements only returns a single table

When I call Store Procedure with 3 select queries in mysql than it returns 3 tables, but when i call it in spring it only returns a single table result. Below is the code calling Stored Procedure in Spring.

@ResponseBody
    @RequestMapping(value="/", method=RequestMethod.GET, produces="application/json", headers="Accept=application/json")
    public String listProducts() throws ParseException {
        int id=1;
        int days=20;
        Query query = session.createNativeQuery("{call getWalkInInfo(?,?)}", Product.class);
        query.setParameter(1,id);
        query.setParameter(2,days);
        Gson gson=new Gson();
        String jsonArray=gson.toJson(query.getResultList());
        System.out.println(jsonArray);
        return jsonArray;
    }

You need to create 3 OUTPUTs in your stored procedure

for example MSSQL server :

ALTER PROCEDURE [dbo].[Procedure_name]
(
@Id_user int,
@select_one int output,
@select_two decimal(10,2) output,
@select_three decimal(10,2) output 
)
AS

BEGIN

set @select_one = (select * from table1);
set @select_two = (select * from table2);
set @select_three = (select * from table3);

END

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