我有一个像这样的存储过程,它将记录插入到几个表中
CREATE PROCEDURE [dbo].[DEL_BPM_RT_DATA_BY_FILTERS] ()
AS
BEGIN
DECLARE @ARC_PROCESS_INSTANCE_DATA VARCHAR(MAX);
DECLARE @ARC_PROCESS_ACTIVITY VARCHAR(MAX);
DECLARE @ARC_BUSINESS_IDENTIFIER_STRING VARCHAR(MAX);
SET @ARC_PROCESS_INSTANCE_DATA = 'INSERT INTO PROCESS_INSTANCE_DATA_ARC SELECT * FROM PROCESS_INSTANCE_DATA WHERE INSTANCE_ID IN (SELECT ID FROM #TEMP_PROCESS_INSTANCE)';
SET @ARC_PROCESS_ACTIVITY = 'INSERT INTO PROCESS_ACTIVITY_ARC SELECT * FROM PROCESS_ACTIVITY WHERE INSTANCE_ID IN (SELECT ID FROM #TEMP_PROCESS_INSTANCE)';
SET @ARC_BUSINESS_IDENTIFIER_STRING = 'INSERT INTO BUSINESS_IDENTIFIER_STRING_ARC SELECT * FROM BUSINESS_IDENTIFIER_STRING WHERE INSTANCE_ID IN (SELECT ID FROM #TEMP_PROCESS_INSTANCE)';
BEGIN
EXEC (@ARC_PROCESS_INSTANCE_DATA);
EXEC (@ARC_PROCESS_ACTIVITY);
EXEC (@ARC_BUSINESS_IDENTIFIER_DATE);
END;
这个存储过程是从JAVA这样调用的。
try {
.
.
.
dbConnection.setAutoCommit(false);
CallableStatement stmt = dbConnection.prepareCall("{call DEL_BPM_RT_DATA_BY_FILTERS}");
stmt.execute();
dbConnection.commit();
} catch (SQLException e) {
e.printStacktrace();
}
时不会抛出异常
EXEC (@ARC_PROCESS_ACTIVITY);
EXEC (@ARC_BUSINESS_IDENTIFIER_DATE);
无法执行(未创建所需的表以使其失败)。但是,如果第一个可执行语句失败,即EXEC (@ARC_PROCESS_INSTANCE_DATA);
如何在所有情况下抛出异常,无论是第一个语句失败还是任何语句?
我不想将该存储过程放在像BEGIN TRANSACTION
这样的事务中。
我使用的是sql server 2008 R2
提前致谢。