views:

342

answers:

2

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:

  1. Why are .execute() and .executeUpdate() behaving differently? From the SUN documentation of the interface it seems that they should do (almost) the same thing...
  2. 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.

A: 

don't know anything about Sybase but

executeUpdate returns more infos than execute : the # of rows inserted/updated/deleted

-> it is usable with UPDATE INSERT DELETE, and DML operations according to the javadoc.

executeQuery returns a ResultSet, this is for SELECT statements.

chburd
+1  A: 

Because those Sybase people are crazy, that's why it eats Exceptions! There's no reason to avoid using executeUpdate() for prepared/callable statements. If that's what you've got to use to get it working then go ahead and do so. But you ought to file a bug report with Sybase - there's no reason the driver should be doing that.

Adam Hawkes