2016-02-07 31 views
0
CREATE PROCEDURE [dbo].[USP_TESTEXCEPTION] 
    @Param1 AS INT, 
    @Param2 AS INT 
AS 
BEGIN 
    SET NOCOUNT ON; 

    UPDATE TABLE1 SET COLUMN1 = @Param1 

    SELECT @Param1, @Param2; // This select is causing problem. 

    SELECT @Param/0; 

    UPDATE TABLE2 SET COLUMN2 = @Param2 
END 

我正在使用SQL Server 2012后端的Spring MVC项目。 我从DAO层调用以下SP,事务从应用程序层处理。 问题是此过程没有引发应用程序层中的任何异常,并且发生了部分事务(TABLE1正在更新,而TABLE2未更新)。 为什么这个SP不会引发应用层中的异常?Java应用程序层不捕获SQL存储过程异常

回答

1

,您将需要使用try渔获物和XACT_ABORT上

alter proc usp_test 
as 
begin 
set nocount on 
set xact_abort on 
begin try 
select 1 
select 1/0 
select 2 
end try 
begin catch 
declare @errormessg varchar(max) 
raiserror(@errormessg,16,1); 
end catch 
end 
+0

看到这个[链接](http://stackoverflow.com/questions/34870909/sql-stored-procedure-exception-not-found-在-JAVA)。我已经尝试过了。但没有运气。 – Esty

+0

哦... XACT_ABORT开启。那就是魔法字..什么? – Esty

+0

all or nothing。更多信息here..http://stackoverflow.com/questions/1150032/what-is-the-benefit-of-using-set-xact-abort-on-in-a-stored-procedure – TheGameiswar

相关问题