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

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

  • Comments 2

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.

Leave a Comment
  • Please add 6 and 7 and type the answer here:
  • Post
Page 1 of 1 (2 items)