Java jdbc executeQuery () works but does () not (multiple result)

I am trying to grab all tables returned by sp_configure (sybase); which returns about 25 tables.

When executing the sql statement using executeQuery function, I can only get the first table that is the target of this function: grabbing only one table in the result:

PreparedStatement stmt = connection.prepareStatement("sp_configure", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
    //grab data from rs here
}
rs.close();

      

Here "rs" is not null and contains the data of the first result table.

So I need to use the "execute" function, with which I can grab all ResultSets, iterate over them with the getMoreResults () function.

I'm doing it:

PreparedStatement stmt = connection.prepareStatement("sp_configure", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
boolean results = stmt.execute();

while (results) {
    ResultSet rs = stmt.getResultSet();
    while (rs.next()) {
        //grab data from rs here
    }
    rs.close();
    results = stmt.getMoreResults();
} 

      

But execute () returns false!

I tried to use the prepareStatement ("exec sp_configure") syntax, but it still returns false. I also tried prepareStatement ("{sp_configure}") or prepareStatement ("{exec sp_configure}"); but the call to prepareStatement method failed.

Finally, I tried all the same things with "CallableStatement stmt = connection.prepareCall ..."; with the same results.

What am I doing wrong?

Note. I am using jconnect60.jar to connect to my database.

Decision

The working solution given in Daniel's note also checks getUpdateCount (), for example:

CallableStatement stmt = connection.prepareCall("{call sp_configure}", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
boolean isResulset = stmt.execute();
int updResult = stmt.getUpdateCount();

while (isResulset || (updResult != -1)) {

    if (isResulset) {
        rs = stmt.getResultSet();
        while (rs.next()) {

        }
        rs.close();
    }
    isResulset = stmt.getMoreResults();
    updResult = stmt.getUpdateCount();
} 
stmt.close();

      

+3


source to share





All Articles