0

I looks like JDBC.executeQuery() for multi-statement "select into; select @@rowcount" should throw "The statement did not return a result set" exception and it doesn't - is this a bug or a feature?

Note: My problem is to reproduce an exception when executing JDBC.executeQuery("select into; select @@rowcount") - all my out of box SQL Servers returns result set without an exception.

Note: Of course, execute() should be OK and it's second result is a result set.

Note: Already asked this question on following other sites with no correct answer so far:

Sam Mesh
  • 49
  • 4
  • `SELECT @@rowcount` returns a resultset with one row, one colums being the latest @@rowcount. I don't see why you conclude that it should not return a result set. Maybe I misunderstood your problem... – TT. Sep 03 '14 at 10:54
  • So, it's OK that for multiple statements JDBC.executeQuery() doesn't throw an exception and return a result set from the last statement? – Sam Mesh Sep 03 '14 at 17:18
  • From the documentation I gather that **if** Statement.executeQuery that if it doesn't throw, it **will** return a ResultSet object (never null). Since the first statement does not return a result it will return a resultset for the second statement. Documentation does not state clearly what conditions result in an Exception being thrown. – TT. Sep 03 '14 at 18:57
  • http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#executeQuery(java.lang.String) states that exception is thrown if "the given SQL statement produces anything other than a single ResultSet object". Multi-statement definitely produces multiple results, not just a single ResultSet. – Sam Mesh Sep 05 '14 at 18:41

1 Answers1

0

Possible duplicate of The statement did not return a result set. Java Error and JDBC SQL SERVER: The statement did not return a result set

It looks like select into is a DDL statement and should use executeUpdate instead of executeQuery

Tom Slabbaert
  • 21,288
  • 10
  • 30
  • 43
j.con
  • 879
  • 7
  • 19
  • Thank you for response but this doesn't solve my problem. I updated original post with more exact clarification of what is my problem - My problem is to reproduce an exception when executing JDBC.executeQuery("select into; select @@rowcount") - all my out of box SQL Servers returns result set without an exception. – Sam Mesh Sep 03 '14 at 08:36