0

存储过程

CREATE PROCEDURE Proc1
AS
BEGIN
DECLARE @retVal int,
    @Err    int,
    @Rows   int

SELECT @retVal = isnull(max(col1), 0) + 1 FROM Table1

BEGIN tran

INSERT INTO Table1(
    col1,
    col2

)
VALUES(@col1,@col2)

SELECT @Err = @@error, @Rows = @@rowcount

IF @Err != 0 or @Rows != 1
BEGIN
     rollback tran
     return -75
END

commit tran
return @retVal
END

Java 代码

public class InsTable1 extends StoredProcedure implements Executable
{


    public InsTable1 (DataSource dataSource)
    {
        super(dataSource, "Proc1");


        super.declareParameter(new SqlOutParameter("retval", Types.INTEGER));

        super.compile();


    }



    public String executeQuery()
    {
        String retval = "";
        Map<String, Object> inParams = new HashMap<String, Object>(1);

        Map outParams = execute(inParams);

        retval = outParams.get("retval") == null ? "" : outParams.get("retval").toString().trim();
        return retval;
    }
}

错误

可调用语句返回的输出参数没有应用程序注册的那么多

记录确实被插入。但即使我删除了输出参数声明,它也不起作用。这里可能的解决方案是什么?

4

1 回答 1

0

您需要获取不是输出参数的返回值。

声明参数时 addwithReturnValue()确保您在 outParams 映射中获得关键“返回”。

我认为您的代码应如下所示:(未测试)

public class InsTable1 extends StoredProcedure implements Executable
{
    public InsTable1 (DataSource dataSource)
    {
        super(dataSource, "Proc1");
        super.declareParameter(new SqlOutParameter("retval", Types.INTEGER));
        super.withReturnValue();
        super.compile();
    }

    public String executeQuery()
    {
        String retval = "";
        Map<String, Object> inParams = new HashMap<String, Object>(1);
        Map outParams = execute(inParams);
        retval = outParams.get("return") == null ? "" : outParams.get("return").toString().trim();
        return retval;
    }
}
于 2013-04-02T15:02:02.153 回答