File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes cs.executeQuery() throws Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "cs.executeQuery() throws "Query returned no data" error" Watch "cs.executeQuery() throws "Query returned no data" error" New topic
Author

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

Andrei Antonescu
Ranch Hand

Joined: Jul 08, 2010
Posts: 75
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

Joined: Aug 22, 2010
Posts: 3611
    
  60

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

Joined: May 19, 2006
Posts: 105
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.

If you worry you cannot work... If you work you need not worry
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

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...


SCJP 6 [SCJP - Old is Gold]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

oh oh sorry for misinformation.. I learned it now
Andrei Antonescu
Ranch Hand

Joined: Jul 08, 2010
Posts: 75
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cs.executeQuery() throws "Query returned no data" error