SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Meir Gold wrote:Actually, I do have a result.
If I place the int id=rs.getInt(1); command immediately after running the query, I get the result I'm expecting.
I also ran the same query using Microsoft SQL Management Studio and could clearly see the result.
I tried the same on a query that returns 22 results and could clearly see that I wasn't getting the expected result in the id=rs.getInt(1).
Meir
~Bill
Meir Gold wrote:The code is similar, it's just a different query:
As the query now returns more results, I would have expected the id=rs.getInt(1); to return the ID number of the first result. Instead it returns the number of the 3rd or 4th result.
I also tracked this with the debugger and can clearly see the currentrow value of the rs variable progressing after each command.
Meir
Meir Gold wrote:Thanks Wendy.
I do have a check for rs.first(), I left it out just to make my question less complicated.
Meir
~Bill
Martin Vajsar wrote:I had experienced the weirdest errors in Java caused by the project not being correctly recompiled. It had happened to me more than once in NetBeans. I don't remember debugging a project in such a state, so I cannot comment on these observations. Nowadays I tend to always use Clean and Build to compile the project, which takes a long time, but does recompile all source files.
NetBeans also sometimes report errors in perfectly good code, in which case it usually helps to erase the NetBeans cache from user profile. These two are probably unrelated problems, though.
~Bill
Bill Johnston wrote:
Meir Gold wrote:Thanks Wendy.
I do have a check for rs.first(), I left it out just to make my question less complicated.
Meir
But the truth is that is doesn't make it less complicated; it makes it more complicated. And similar code isn't the same as the exact code. Please don't read this the wrong way - I'm not being sarcastic or accusative but instructional ... at least that is how I intend this. You should always post the exact code snippet, byte for byte that you run, and the exact errors and exceptions you are getting as well. If the code would be too much to post, then you should make a smaller version of the code that demonstrates the problem and post that (in this instance apparently that isn't the case though). Again, just a friendly reminder.
Now as to the problem; I have seen very strange things happen in C regarding printf statements changing logic flow, and in one case I never did figure it out. But never in Java. I'd be desirous of following up on this if it was me. Regards,
Wendy Gibbons wrote:also remember printf will format varaibles for you, that is why debugging changed the flow.
~Bill
Bill Johnston wrote:
Wendy Gibbons wrote:also remember printf will format varaibles for you, that is why debugging changed the flow.
I don't follow you, Wendy. In the case I mentioned this was a very rare instance where adding a printf statement changed the program flow. As I recall, I printed nothing; was just something like .
Wendy Gibbons wrote:
Bill Johnston wrote:
Wendy Gibbons wrote:also remember printf will format varaibles for you, that is why debugging changed the flow.
I don't follow you, Wendy. In the case I mentioned this was a very rare instance where adding a printf statement changed the program flow. As I recall, I printed nothing; was just something like .
I was thinking about strings with funny stuff in them, they would crash unless you output them. But also any code changes memory addresses so if you were accessing a dodgy pointer it now looked somewhere else for it's dodgy data.
~Bill
Meir Gold wrote:As the query now returns more results, I would have expected the id=rs.getInt(1); to return the ID number of the first result. Instead it returns the number of the 3rd or 4th result.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Don't get me started about those stupid light bulbs. |