简体   繁体   English

存储过程不返回结果集

[英]Stored procedure doesn't return a resultset

I'm trying to fetch data using this stored procedure: 我正在尝试使用此存储过程获取数据:

create procedure Proc_Member_Statement @Counter int,@TransDate datetime
as
declare @schemeNo int,@MemberNo int

select @schemeNo = SchemeNo,@MemberNo = MemberNo from Members where Counter = @Counter

exec Individualize @schemeNo,@MemberNo,@TransDate,0,0

exec RepMemberCertificate_DBN_One @schemeNo,@MemberNo,@TransDate,0

My model class: 我的模特班:

    @NamedStoredProcedureQueries(
        {

                @NamedStoredProcedureQuery(
                        name = "getMemberStatement",
                        procedureName = "Proc_Member_Statement",
                        resultClasses = AccountStatement.class,
                        parameters = {
                                @StoredProcedureParameter(
                                        name = "Counter",
                                        mode = ParameterMode.IN,
                                        type = Long.class

                                ),
                                @StoredProcedureParameter(
                                        name = "TransDate",
                                        mode = ParameterMode.IN,
                                        type = Date.class

                                )
                        }
                ),
        }

)
@Entity
public class AccountStatement implements Serializable {

    @Id
    BigDecimal EmpOpBal;

    public BigDecimal getEmpOpBal() {
        return EmpOpBal;
    }

    public void setEmpOpBal(BigDecimal empOpBal) {
        EmpOpBal = empOpBal;
    }

    public BigDecimal getEmprOpBal() {
        return EmprOpBal;
    }

    public void setEmprOpBal(BigDecimal emprOpBal) {
        EmprOpBal = emprOpBal;
    }

    public BigDecimal getEmpCont() {
        return EmpCont;
    }

    public void setEmpCont(BigDecimal empCont) {
        EmpCont = empCont;
    }

    public BigDecimal getEmprCont() {
        return EmprCont;
    }

    public void setEmprCont(BigDecimal emprCont) {
        EmprCont = emprCont;
    }

    public BigDecimal getEmpVolCont() {
        return EmpVolCont;
    }

    public void setEmpVolCont(BigDecimal empVolCont) {
        EmpVolCont = empVolCont;
    }

    public BigDecimal getEmprVolCont() {
        return EmprVolCont;
    }

    public void setEmprVolCont(BigDecimal emprVolCont) {
        EmprVolCont = emprVolCont;
    }

    public BigDecimal getEmpInt() {
        return EmpInt;
    }

    public void setEmpInt(BigDecimal empInt) {
        EmpInt = empInt;
    }

    public BigDecimal getEmprInt() {
        return EmprInt;
    }

    public void setEmprInt(BigDecimal emprInt) {
        EmprInt = emprInt;
    }

    public BigDecimal getClosingBal() {
        return ClosingBal;
    }

    public void setClosingBal(BigDecimal closingBal) {
        ClosingBal = closingBal;
    }

    public BigDecimal getEmpCBal() {
        return EmpCBal;
    }

    public void setEmpCBal(BigDecimal empCBal) {
        EmpCBal = empCBal;
    }

    public BigDecimal getEmprCBal() {
        return EmprCBal;
    }

    public void setEmprCBal(BigDecimal emprCBal) {
        EmprCBal = emprCBal;
    }


    @Id
    BigDecimal EmprOpBal; // Employer Opening Balance
    @Id
    BigDecimal EmpCont; //Reg Employee
    @Id
    BigDecimal EmprCont; //Reg Employer
    @Id
    BigDecimal EmpVolCont; //Employee AVC
    @Id
    BigDecimal EmprVolCont; //Employer AVC
    @Id
    BigDecimal EmpInt; //Employee Interest
    @Id
    BigDecimal EmprInt; //Employer Interest
    @Id
    BigDecimal ClosingBal; //Closing Balance (Total)
    @Id
    BigDecimal EmpCBal; // Employee Closing Balance
    @Id
    BigDecimal EmprCBal; // Employer Closing Balance


}

Now when I try to run the stored procedure so I can get values from the database, I keep getting this error: 现在,当我尝试运行存储过程以便从数据库中获取值时,我不断收到此错误:

[java.lang.IllegalStateException: Current CallableStatement ou was not a ResultSet, but getResultList was called] [java.lang.IllegalStateException:当前的CallableStatement ou不是ResultSet,但是调用了getResultList]

Here is the bean class: 这是bean类:

public List<AccountStatement> getOpeningBalances(long memberId, Date date) {

        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, -3);
        jLogger.i("Calender >>>>> " + cal.getTime());

        StoredProcedureQuery query = this.entityManager.createNamedStoredProcedureQuery("getMemberStatement");
        query.setParameter("Counter", memberId);
        query.setParameter("TransDate", cal.getTime());
        query.execute();
        try {
            jLogger.i("Returned result >>>>>>>>>> " + query.getResultList());
            List<AccountStatement> openingBalances = query.getResultList();
            return openingBalances;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

What I'm i doing wrong? 我做错了什么?

EDIT: Here is part of the output when I run the stored procedure in Microsoft SQL Server Management Studio: 编辑:这是我在Microsoft SQL Server Management Studio中运行存储过程时输出的一部分:

样本输出

I intend to use data from some of the columns within the system. 我打算使用系统中某些列中的数据。 Thanks. 谢谢。

It's still not clear where the resultset you're expecting is coming from, I suspect from one of the stored procedures that's called within Proc_Member_Statement. 我怀疑您期望的结果集来自何处,我怀疑来自Proc_Member_Statement中调用的存储过程之一。

In order to get the results set out of Proc_Member_Statement you will need to insert the result set from the stored proc into a temporary table, and then at the end of Proc_Member_Statement SELECT the rows from it. 为了从Proc_Member_Statement中获取结果集,您需要将存储的proc中的结果集插入到临时表中,然后在Proc_Member_Statement的末尾选择其中的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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