I'm using the official Sybase JDBC driver to connect to a database and call a stored procedure by creating a CallableStatement, binding the parameters to it and calling .execute() on it.
However, I found that no exception is thrown, even if the stored procedure fails. I can verify that the failure is propagated back to me by sniffing the traffic to the database with Wireshark and observing the error messages coming back.
Finally I found that using .executeUpdate() instead of .execute() does give me the exceptions, however I still have two questions left:
- Why are .execute() and .executeUpdate() behaving differently? From the SUN documentation of the interface it seems that they should do (almost) the same thing...
- Is it always appropriate to replace .execute() with .executeUpdate() when calling a stored procedure? Must the stored procedure conform to some particular requirements to be callable with .executeUpdate()? (for example, must it have an update/delete/insert statement as the last step?)
Update: I've tried jTDS, and it behaves correctly (as in: it throws the SQLException in both cases - with .execute() and with .executeUpdate()). However, due to constraints beyond my control, switching out the driver is not really possible.
Also: I'm no interested in the result returned by this stored procedure, it is an insert/update type procedure. I would only be inserted to see (and be able to catch / log) if it fails or not. An other thing I've tried is to get the warnings off the connection after .execute(), but it didn't contain anything either.