I'm uncertain as to how to get the number of rows affected from a SQL execution.
I do like this:
boolean isResultSet = statement.execute(arbitrarySQLCommand);
and I can get the number of rows affected from the getUpdateCount() method. That is all fine. The problem I have is when update count is zero. This can either mean:
It was a DML statement but it didn't affect any rows. Zero rows affected is a valid response. I just means that some condition was not met.
It was a non-DML statement (DDL statement most likely) .. which by definition does not change rows so therefore update count is always zero (duh!). Or to put it another way: The concept of update count is meaningless for such statements.
What I would like is to be able to distinguish between situation 1 and 2 above. How?
I'm not interested in statements that produce output so I could also use executeUpdate() but as I see it the return value from that method has the same flaw:
Returns:
either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
Arghhh!
I wish it was:
Returns:
either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) -1 for SQL statements that return nothing
(note: I do not know the contents of arbitrarySQLCommand beforehand)
Final chosen solution
There just doesn't seem to be a true JDBC-like solution to the problem. In my mind the designers of JDBC has made a serious mistake on the getUpdateCount by using the