This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes No data found error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "No data found error" Watch "No data found error" New topic

No data found error

krupa devi

Joined: Jul 02, 2001
Posts: 14
I am using sun's JDBC driver and I am calling a stored procedure. I am getting the data. But before showing the data if I do a comparison like myresultset.getString(4) == "0" then
show data else skip, then I am getting an error saying no data found, otherwise I am getting the data.
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
Just check whether the column number that you are using in the getString() function is correct?
it may be possible that you are comparing with wrong column values reteived in the resultset. It happens quite often that within our select query we change the sequence of the column names and thus result in error.
Best way is to use the column name in getString function.

Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
Mohamed Yousuff
Ranch Hand

Joined: Jun 23, 2001
Posts: 73

This is a simple problem to solve. You have to understand that resultset is always a forward-only cursor. Also, for the current cursor position, you cannot retrieve the value twice using the getString() function or any other getxxx() method. What you need to do is store it in a temporary variable and then use it. You can use like
String temp = myresultset.getString(4) ;
if ( temp.equals("0") ) then
show data
skip and do normal operations

Hope you understand the solution


Joined: Jun 25, 2001
Posts: 10
"You have to understand that resultset is always a forward-only cursor."
I hope you are not suggesting that all resultsets are type forward only. Surely you are aware of ResultSet.TYPE_SCROLL_INSENSITIVE. Also, I can use the getXXX(1) method as many times on a resultset row as needed. example code snippet that was pulled from one of my programs:
String query = "select * from emp"
statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
results = statement.executeQuery(query);
System.out.println("results.getString(1) = " + results.getString(1));
System.out.println("results.getString(1) = " + results.getString(1));
maybe I misunderstood what you were implying by the above statement but in numerous situations I use a scrollable resultset accessing each data with the getXXX method many times.
krupa devi

Joined: Jul 02, 2001
Posts: 14
You are right.I was using the same lines of code you showed, but instead of using equals function of the string class I used "==". when I changed it to equals , it worked. also when I tried to use the same rs.getString(3) again, I got no datafound error. When I replaced it with the temporary variable it worked.
Thanks for the help.

Joined: Jun 25, 2001
Posts: 10
Which database are you using? I've never come accross a problem of calling getXXX more than once and receiving a no data found exception!
Is this common to many database vendors?


subject: No data found error
Similar Threads
Unable to look up JNDI name for JMS connection factory from one weblogic server to o
BEA Weblogic certification guide from GAMMA
Download SCEA 310-051 Free Exam Simulator
JDBC_ODBC bridge
data connection pool