Іван Гладуш
Іван Гладуш

Reputation: 385

How to receive all ResultSets from Statement from JDBC?

I execute the following queries:

SELECT 1; CREATE TABLE ....; SELECT 2;

after that I try to get all resultSets. I use the following code for this:

while(!stmt.getMoreResults()) {
 stmt.getResultSet();
}

Unfortunately I get jus first result set. Please tell me what I'm doing wrong?

Upvotes: 2

Views: 196

Answers (2)

DShevelev
DShevelev

Reputation: 91

Are you trying to say that Java is just not capable of doing the thing .Net does without a hitch? Is it as simple as that? No matter what kind of dummy statements are between selects in the script that is run as batch the bool IDataReader.NextResult() in the C# code reliably returns next result jumping over the next dummy statements for Netezza we are trying to debug for now. It did the same thing for many years for all the platforms that support batch calls in case we had to deal with them. enter image description here

Upvotes: 2

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520938

Your second CREATE TABLE statement technically does not even return a result set (though JDBC might return a count of the records affected by DML). So, if you want to capture the conceptual return value of each statement, then you should just run them separately.

If your second statement were actually a SELECT, then perhaps we could find some way to combine the queries together.

Read this canonical answer to see how to handle the case where you really do have mulitple selects. But, note that not all databases support this (e.g. Oracle does not support it). And read here to see why multiple queries in a single JDBC call might even be a bad thing.

Upvotes: 3

Related Questions