dcsimg
<p><pre><font size="3">Question on PreparedStatement.executeQuery()<br>that returns a ResultSet.</font></pre></p>
5 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Varghese_Samuel
Posted On:   Wednesday, February 6, 2002 10:08 PM

			
Can anyone give a solution on how to handle
the resultSet return value on executing
the statement:
PreparedStatement.executeQuery() ,when the statement
returns zero number of records.


			
As in my case it gives the "invalid cursor status" error
as soon as the statement:
ResultSet=PreparedStatement.executeQuery() gets executed.


			
Is there any way to know that
the particular resultset is void of any records.

Re: <p><pre><font size="3">Question on PreparedStatement.executeQuery()<br>that returns a ResultSet.</font></pre></p>

Posted By:   David_Liu  
Posted On:   Thursday, February 7, 2002 08:09 AM

That doesn't sound right. You should provide more code segments. The probability of return zero is common. The error handling is already build in to the code, and you should not have to do any pre-checking prior to the execute.


I am curious to see the line of code you have AFTER your executeQuery() statement.


Here is what it should look like:


statement = conn.createStatement();
rs = statement.executeQuery(query) ;
while ( rs.next() )
{
// this should work
}

Re: <p><pre><font size="3">Question on PreparedStatement.executeQuery()<br>that returns a ResultSet.</font></pre></p>

Posted By:   Bozidar_Dangubic  
Posted On:   Thursday, February 7, 2002 07:25 AM

executeQuery() should not throw this exception unless you are using the Connection that is currently in use. Regardless of how many record(s) are returned and stored in the result set object (0 to many) this call will not throw an exception. Exception are reserved for when something goes awry. A query that returns nothing does not indicate the Exception. it simply indicates that no records in the database satisfy the search criteria provided in the query. after the call to executeQuery() you can test if there is any data returned by calling rs.next(). if this call returns false, it means that there is no data in the ResultSet, i.e. you query did not produce any errors. Counting before executing is very wasteful. So check and make sure that the Connection object you are using is not currently in use. I have gotten this same exception at times when I accidentally reused the connection that was in the middle of execution or had a ResultSet bound to it.

Re: <p><pre><font size="3">Question on PreparedStatement.executeQuery()<br>that returns a ResultSet.</font></pre></p>

Posted By:   Bozidar_Dangubic  
Posted On:   Thursday, February 7, 2002 07:25 AM

executeQuery() should not throw this exception unless you are using the Connection that is currently in use. Regardless of how many record(s) are returned and stored in the result set object (0 to many) this call will not throw an exception. Exception are reserved for when something goes awry. A query that returns nothing does not indicate the Exception. it simply indicates that no records in the database satisfy the search criteria provided in the query. after the call to executeQuery() you can test if there is any data returned by calling rs.next(). if this call returns false, it means that there is no data in the ResultSet, i.e. you query did not produce any errors. Counting before executing is very wasteful. So check and make sure that the Connection object you are using is not currently in use. I have gotten this same exception at times when I accidentally reused the connection that was in the middle of execution or had a ResultSet bound to it.

Re: <p><pre><font size="3">Question on PreparedStatement.executeQuery()<br>that returns a ResultSet.</font></pre></p>

Posted By:   Bozidar_Dangubic  
Posted On:   Thursday, February 7, 2002 07:25 AM

executeQuery() should not throw this exception unless you are using the Connection that is currently in use. Regardless of how many record(s) are returned and stored in the result set object (0 to many) this call will not throw an exception. Exception are reserved for when something goes awry. A query that returns nothing does not indicate the Exception. it simply indicates that no records in the database satisfy the search criteria provided in the query. after the call to executeQuery() you can test if there is any data returned by calling rs.next(). if this call returns false, it means that there is no data in the ResultSet, i.e. you query did not produce any errors. Counting before executing is very wasteful. So check and make sure that the Connection object you are using is not currently in use. I have gotten this same exception at times when I accidentally reused the connection that was in the middle of execution or had a ResultSet bound to it.

Re: Question on PreparedStatement.executeQuery()that returns a ResultSet.

Posted By:   Benoit_Quintin  
Posted On:   Thursday, February 7, 2002 06:21 AM

I would check the ResultSet's MetaData for info on your data.

Also, you might want to "select count(*) from TABLE" before passing your query to your DB....
About | Sitemap | Contact