存储过程
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;
}
}
错误
可调用语句返回的输出参数没有应用程序注册的那么多
记录确实被插入。但即使我删除了输出参数声明,它也不起作用。这里可能的解决方案是什么?