• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Everybody! Do the Funky Monkey! Like this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic