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
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);
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
"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.
Joined: Jul 02, 2001
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
Joined: Jun 25, 2001
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?