SQL Stored Procedure Exception Not Found in JAVA

。_饼干妹妹 提交于 2020-01-06 20:09:59

问题


Throwing exception from sql stored procedure catch block is not raising exception in java layer for SP1 while for SP2 exception raised.

When I am executing both SPs are giving exception in SQL Server but from java code I got no exception for SP1.

I am calling both SPs using JPA StoredProcedureQuery and using Hibernate & Spring.

CREATE PROCEDURE SP1
AS
SET NOCOUNT ON

BEGIN TRY
DECLARE @ErrorMessage AS VARCHAR(MAX)
SELECT 1/0
END TRY

BEGIN CATCH
THROW 50001, @ErrorMessage, 1;
END CATCH


CREATE PROCEDURE SP2
AS
SET NOCOUNT ON

DECLARE @ErrorMessage AS VARCHAR(MAX)
SELECT 1/0
if @@error<>0
GOTO Erro

RETURN
Erro:
THROW 50001, @ErrorMessage, 1;

I have tested that if I use any THROW in TRY block it raise exception in Java side while in CATCH block its not.

来源:https://stackoverflow.com/questions/34870909/sql-stored-procedure-exception-not-found-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!