Why doesn't executeUpdate() give me the exception I expected?
Published Mar 23 2019 11:00 AM 379 Views
First published on MSDN on Aug 04, 2008

If you are using executeUpdate() to execute a query or stored procedure containing multiple SQL statements, the problem may just be that the error you're expecting wasn't the first result returned by the query.  Consider a case where you use executeUpdate() to call a stored procedure containing multiple SQL statements, and the first result is an update count (from INSERT, for example), followed later by some error.  Since executeUpdate() expects only a single update count, it returns the one for the INSERT statement as soon as it encounters it, leaving the error that follows it waiting to be retrieved.  If you want your application to “see” that error (thrown as exception by the driver) and any subsequent results, you need to call the stored procedure using execute() and process all of the results using getMoreResults().  See this post for details.

--David Olix [SQL Server]

This post is provided 'as is' and confers no express or implied warranties or rights.

Version history
Last update:
‎Mar 23 2019 11:00 AM
Updated by: