You are misinterpreting the return value of getMoreResults() . You also ignore the return value of execute() , this method returns a boolean indicating the type of the first result:
true : result: ResultSetfalse : result - the number of updates
If the result is true , you use getResultSet() to retrieve the ResultSet , otherwise getUpdateCount() to get the number of updates. If the number of updates is -1 , then there are no more results. Note that the number of updates will also be -1 if the current result is ResultSet . It is also useful to know that getResultSet() should return null if there are no more results or the result is equal to the number of updates (this last condition is why you get so many null values).
Now, if you want more results, you call getMoreResults() (or his brother accepts an int parameter). The return value of boolean has the same value as the value of execute() , so false does not mean that there are no more results!
Results if getMoreResults() returns false and getUpdateCount() returns -1 (as also described in Javadoc)
Essentially this means that if you want to process all the results correctly, you need to do something like below:
boolean result = stmt.execute(...); while(true) { if (result) { ResultSet rs = stmt.getResultSet(); // Do something with resultset ... } else { int updateCount = stmt.getUpdateCount(); if (updateCount == -1) { // no more results break; } // Do something with update count ... } result = stmt.getMoreResults(); }
I assume you get a lot of updates before you get the actual ResultSet .
I'm not very good at Sybase, but his cousin SQL Server has an "annoying" function to return update counts from stored procedures unless you explicitly put SET NOCOUNT ON; at the beginning of the stored procedure.
NOTE. Part of this answer is based on my answer to Running "sp_msforeachdb" in a Java Application
source share