3

I'm trying to grab all the tables returning by the command sp_configure (sybase); which returns about 25 tables.

When executing the sql statement with executeQuery function, I can only retrieve the first table, which is the purpose of this function: grabbing only one table in 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 first result table data.

So I have to use the "execute" function with which I can grab all ResultSet by iterating over them with the function getMoreResults().

I'm doing this:

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() return false!

I've tried to use the syntax prepareStatement("exec sp_configure") but it's still returning false. I've also tried prepareStatement("{sp_configure}") or prepareStatement("{exec sp_configure}"); but the call to prepareStatement failed.

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

What I'm doing wrong?

Note: I'm using jconnect60.jar to connect to my database.

Solution

The working solution given in note by Daniel is to check getUpdateCount() too, like this:

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();
Alexxx
  • 766
  • 1
  • 11
  • 19
  • 3
    Maybe this can point you in the right direction: http://stackoverflow.com/questions/14829130/null-resultsets-when-calling-sybase-stored-procedure-through-jdbc – Daniel Sep 19 '14 at 12:47
  • Good point! It's working now. I also have to check getUpdateCount()! – Alexxx Sep 19 '14 at 13:01

0 Answers0