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
java sybase jdbc resultset


source to share


No one has answered this question yet

See similar questions:

4
Null results when calling Sybase stored procedure via JDBC

or similar:

2248
Is a finally block always executable in Java?
1367
Fastest way to determine if an integer square root is an integer
1249
How does the Java loop for each loop work?
1215
Why is Java code executed in comments with some Unicode characters?
911
Getting the current working directory in Java
778
How do I execute a method execution in Java?
1
Can I modify the executable SQL prior to execution with the AspectJ pointcut
1
How can I execute a stored procedure without a query in JDBC
1
Can ResultSet be "null" in Java?
0
resultset.last () throws an exception in java



All Articles
Loading...
X
Show
Funny
Dev
Pics