Web services 显示当前标识(“tbluser”),但无法看到当前标识&“x27”;d数据
我使用的是sql server 2008,它与java web服务通信,java web服务与asp.net应用程序通信。 我编写了如下存储过程:Web services 显示当前标识(“tbluser”),但无法看到当前标识&“x27”;d数据,web-services,sql-server-2008,Web Services,Sql Server 2008,我使用的是sql server 2008,它与java web服务通信,java web服务与asp.net应用程序通信。 我编写了如下存储过程: create procedure abc(@intA int,@intB int,@intOutputParameter int output) as begin insert into tbluser(A,B) values (@intA,@intB) /*where B is foregin key */
create procedure abc(@intA int,@intB int,@intOutputParameter int output)
as
begin
insert into tbluser(A,B) values (@intA,@intB)
/*where B is foregin key */
set @intOutputParameter = IDENT_CURRENT ('tbluser')
end
/*where B is foregin key */
--现在,当我以主表中不存在的形式传递B时,它抛出了一个错误(在SQLServer2008中),这是完全可以接受的
但是在java web方法s中,我的sp被执行,我的insert语句没有被执行,insert之后的语句直接被执行(identity_current(“Tbluser”)…为什么会这样
如果您需要更多的解释,请询问……a)您的@intOutputParameter
参数未声明为输出;使用:
CREATE PROCEDURE abc (
@intA int
,@intB int
,@intOutputParameter int OUTPUT
)
AS
b) 您确定表tbluser
具有类似id int-IDENTITY(1,1)
的内容吗
c) “开始”和“结束”是什么意思
更新:您可以通过在过程中使用try-catch来解决此问题,如:
ALTER PROCEDURE abc (
@intA int
,@intB int
,@intOutputParameter int OUTPUT
)
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
/*where B is foregin key */
INSERT INTO tbluser ( A, B ) VALUES ( @intA, @intB )
SET @intOutputParameter = IDENT_CURRENT('tbluser')
END TRY
BEGIN CATCH
SET @intOutputParameter = -1
END CATCH
END
如果出现错误,这将返回-1,因此如果您的表ID大于1,那么Java应用程序可以区分成功插入和错误。抱歉出错。。。是..有标识键,不使用当前标识。使用scope_identity()。Ident_current可能会从其他人插入的记录中为您提供标识值。