2013-04-01 147 views
0

存儲過程沒有得到在Sybase數據庫

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 

使用Spring 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; 
    } 
} 

的錯誤

可調用語句單產值沒有不會返回應用程序已註冊的許多輸出參數

記錄確實被插入。但即使我刪除了輸出參數聲明,它也不起作用。 這裏有什麼可能的解決方案?

回答

0

您需要獲取返回值,這不是輸出參數。

當聲明參數add withReturnValue()它確保你得到一個關鍵「返回」在你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; 
    } 
}