Hi all, I want to compare a string to each of the values I've got from a column. What I was doing was initialising a string array Tester[] and ,using a for loop, inserting each value from each row of the column into Tester[] for further use: boolean val=true; for (int i=1; val=true;i++){ try { Tester[i]=res.getString(i); }catch (Exception e){System.out.println(e);} if (res.isLast()) val= false; else val=true; } The "try" caught an invalid cursor state exception. Can anybody shed some light as to what is going on and how I can solve this problem?? all the best, Alan
ravi janap
Ranch Hand
Joined: Nov 04, 2000
Posts: 389
posted
0
boolean val=true; for (int i=1; val=true;i++){ try { Tester[i]=res.getString(i); }catch (Exception e){System.out.println(e);} if (res.isLast()) val= false; else val=true; } go for val == true rather than val = true inside for loop
SCJP, SCJD, SCWCD, SCBCD, SCEA
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
posted
0
The "val=true" pitfall has already been mentioned. But that's not all. First, "for" idiom. What about
Personally, I find the intermediate "val" variable just confusing. Also this won't fall over on empty resultsets. Second, the use of isLast(). Note that the Javadoc says it may be an expensive operation. Also, it does not advance the cursor - what are you trying to do? If you are trying to retrieve successive records, then you should use next() and get rid of the res.getString(i) argument:
If you're trying to get all the fields in a single result record, neither next() nor isLast() will serve you as both deal with records (rows) rather than columns. Instead:
This would need to be nested within a while(res.next()) loop or similar. - Peter
liverpool alan
Greenhorn
Joined: Nov 08, 2000
Posts: 18
posted
0
Thanks for the help guys.... I used the suggestion about next and after a little tweaking it worked nicely. Also, must include my apologies for the "val=true", that was a typing error. All the best, Alan
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.