Home > Archive > SQL Server JDBC > September 2005 > How to abort stored procedure on error (@@ERROR > 0)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to abort stored procedure on error (@@ERROR > 0)
Radovan Biciste

2005-09-01, 8:23 pm

Hello,
I've posted the following message to programing group. I'm posting it
here in hope that somebody dealt with a similar JDBC problem.

I'm still learning SQL Server. Right now I'm trying to find generic way
to handle exception. I would like to have a stored procedure that would
check @@ERROR and abort execution of parent procedure and raise the
exception to client. We are using JDBC to connect to database.
It should like this:

create procedure a_test as
....
insert into a_table values (1,3,4)
exec dbUtil_pkg$check_err
or(@@ERROR)
update a_table set name='aaa' where id=1
....
end

Right now the problem is that even if there is an exception the stored
procedure continues in execution.
The only way I found so far is to do something like this:

create procedure a_test as
....
insert into a_table values (1,3,4)
if @@ERROR > 0 return @@ERROR
update a_table set name='aaa' where id=1
....
end

It does not raise the exception to a client though. I would have to loop
through all results of queries to retrieve it.
It might help to note that I'm porting our application from Oracle to
SQL Server and we are trying to mimic Oracle's behaviour.
Hope that makes sense,
Radovan
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com