Partager via


Why doesn't executeUpdate() give me the exception I expected?

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.

Comments