Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No data found error

 
krupa devi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
Thanks
Krupa
 
rani bedi
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
getString(column_name);
 
Mohamed Yousuff
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
else
skip and do normal operations

Hope you understand the solution


------------------
 
jlrober
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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);
results.last();
results.first();
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
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohammed,
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.
Krupa
 
jlrober
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Jamie

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic