Thanks for the response Tolls.
Just to recap:
I am using JDBC to connect to a MySql database. I have written a stored procedure that does an UPDATE and then a SELECT. Therefore I have to use the jdbc execute() method since there are multiple results returned to java due to the database update and query.
I have tested it from the MySql client and it does indeed update several rows of a table and then selects a few rows from that table. I have a java class that uses callablestatement and the execute() method of the JDBC api to call the stored proc and retrieve its "results" (i.e: A resultset and an Updatecount).
During my testing I have noticed:
1. According to the Java documentation execute() returns true if the first result is a ResultSet object; false if the first result is an update count or there is no result. In my java class callablestatement.execute() will return TRUE if in the stored proc the UPDATE is done first and then the SELECT last or vica versa.
2. My java class (above) is coded to loop through all results returned from the stored proc in succession. Running this class shows that any resultsets are returned first and then update counts last regardless of the order in which they appear in the stored proc. Maybe there is nothing unusual here, it may be that Java is designed to return any Resultsets first by default even if they didn't happen first in the stored procedure?
3. In my stored procedure, if the UPDATE happens last then callablestatement.getUpdateCount() will return the correct number of updated rows.
4. If the UPDATE is followed by a SELECT (see above) then callablestatement.getUpdateCount() will return ZERO even though rows were updated.
5. I tested it with the stored proc doing SELECT - UPDATE - SELECT and again getUpdateCount() returns ZERO.
6. I tested it with the stored proc doing SELECT - UPDATE - SELECT - UPDATE and this time getUpdateCount() returns the number rows updated by the last UPDATE and not the first.
I take your point about returning rowcounts in OUT parameters but I want my code to be modular enough to cover the situation where a statement may return more than one ResultSet object, more than one update count, or a combination of ResultSet objects and update counts. The sql may need to be generated dynamically, its statements may be unknown at compile time.
Maybe I have exposed a bug in the JDBC api?
Thank you for reading