Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cs.executeQuery() throws "Query returned no data" error

 
Andrei Antonescu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I am using JDBC to connect to a database and execute a stored procedure. I do it like this:


Sometimes the stored procedure returns no data and Java gives me an error (Query returned no data...). How can I differentiate this case from other errors ? I use the code above in a try catch but executeQuery gives me the generic SQLException when the "nodata" happens.

Thanks in advance
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have a stored procedure which sometimes returns a Resultset and sometimes not? I'd suggest to consider some refactoring.

Anyway, this situation should probably be handled by calling execute() instead of executeQuery(). See the Javadoc for details.
 
Siri Naray
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try executing the same query in SQLPLUS and check the result that its giving?? If its giving a output when you run in SQLPlus and no Result Set is returned when you run the same query in the program.. then that means there is error in the program. Otherwise means there are no resultset to be retrieved for this query for that particular condition what ever you are executing.

Hope this helps. If you can provide with code sample here will be able to better understand.
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyway, this situation should probably be handled by calling execute() instead of executeQuery(). See the Javadoc for details.


execute() can only be used if Stored Procedure makes some insertions/updates... For that too, using executeUpdate() is good...
Since i encountered with an issue of not getting data updates through Stored Procedure in Sybase while using "execute()"...
After using "executeUpdate()", its working...

only "executeQuery" has to be used since Andrei's program involves the returning of "ResultSet" from stored procedure...

If no data is returned, as Sirisha's suggestion, you can try in SQLPlus...

If expecting some resultset to be returned for particular inputs, you can better check the conditions in queries of Stored Procedure...
 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ram Narayan.M wrote:
Anyway, this situation should probably be handled by calling execute() instead of executeQuery(). See the Javadoc for details.


execute() can only be used if Stored Procedure makes some insertions/updates...

Nonsense. execute() can be used anywhere executeQuery() or executeUpdate() is used. If it doesn't work, blame the driver, not the interface and its methods.
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh oh sorry for misinformation.. I learned it now
 
Andrei Antonescu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for helping.

The problem was indeed the fact that I was using executeQuery for a procedure that generates a report (the stored procedure may or may not return a "ResultSet").

I change it to "execute()" and got the ResultSet with if(...).. getResultSet() and I'ts working.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic