tough luck.
This has nothing to do with JSP so don't expect an answer here.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Well, that wasn't very nice, was it... since the use of Java code in a JSP file is certainly within the realm of JSP, I can understand why this person posted here... it is an innocent enough question, if you don't want to be helpful, then just don't reply...
Now, Are you trying to check an specific field from the results set or the results set as a whole?
I usually use rs.next()...
If I expect 1 result only, I sometimes use if(rs.next()) ... and when I expect there may be multiple rows, I used while(rs.next())... rs.next() results a boolean and moves the rseults set to the next row in the record, returning true if there is a record and false if their are no more records...
the results ste must be positioned to the first row prior to reading anything so this will always work to find out if you have any rows in your result set... if the first call fails, you have NO results... if it succeeds at least once then you have results...
If you are looking for handling of specific fields within your results set... I usually use the long and arduous method of, for example
if(rs.getString(1)!=null) sMyVar = rs.getString(1);
OR
if(rs.getInt(2) !=0) iMyVar = rs.getInt(2);
Assuming the int value of 0 is not valid here... a null value in a DB gets returned as 0 to the getInt call because an int cannot by null in Java... Whereas, the getString just returns a null string, because Strings can be null...
You can assign the values then check for null... but Usually assign default values to my varibales when I declare them, so I only overwrite these default values if the db values are valid...
i.e.
String sName ="";
... // db select stuff removed
if(rs.getString("user")!=null) sName = rs.GetString("user");
OK, does this help?
Peace,
rgtaylor
Junior Poster in Training
88 posts since Mar 2007
Reputation Points: 10
Solved Threads: 2
scriptlets should NEVER be used, period.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Well, you are certainly entitled to your opinion, but there those of us in the real world would just like to ask that you be a little more polite in how you express it.
There are many people out there who "believe" that Java code should not be mixed in the JSP, and others who believe servlets should never be used, that it should all be in the jsp file...
And some that feel a mixing it up to take advantage of what works best for the given situation is the correct solution.
When you say "NEVER" you show just how silly you are since few things in the world are ever absolute...
They can put such code in a tag library... but I am willing to admit that it is easier for many people to embed the code...
Now, before someone tries to claim a rule such as never do this or never do that, you should ask yourself, why did the JSP Spec then allow <% %> and <%= %> tags if you should "NEVER" use them...
Things that make you go "Hummm?"...
Accept that the world works in many different ways and no one solution is right for everyone and the whole world will be a better place... including cyberspace...
Peace,
rgtaylor
Junior Poster in Training
88 posts since Mar 2007
Reputation Points: 10
Solved Threads: 2
I've been working in the "real world" of JSP development for the last 7 years kid, I've seen it all.
The spec initially didn't include tags, which was later corrected.
The old style syntax was (IMO mistakenly) maintained for backwards compatibility only.
If kids just learned to do things the right way the world would be a much happier place and there'd be no kids like you who think they know it all from having read a 10 year old tutorial that's 6 years out of date.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
You seem to think I am a kid for some reason... You also seem to be inflexible in the idea that there are NO "right ways" to do things... only what works best for each programmer... get over yourself...
I am and have been a professional coder, consultant, systems designer and President & CEO of an IT / Software consulting and design company. I have spent as many years as you claim to have worked with JSP working with the largest Software and Enterprise Solution companies in the world... I think I should, perhaps, be calling you the kid, since your imature attitude shown in many posts I have read on this forum...
I have been programming for nearly 30 years and even now I don't presume to tell other how they "should" or "should't" do things...
You say the tags for embedding code wasn't in the initial spec, but then you say the "old" syntax was maintained for backwards compatibility only... so which is it? new or old... and who are you to decide why things were done, not done... get over yourself...
All this trouble because someone asked for help and you felt the need to give a snide reply instead of being helpful...
reply if you like, but I have had about enough of this discussion, so I think I am finished here... enjoy your small minded world.
rgtaylor
Junior Poster in Training
88 posts since Mar 2007
Reputation Points: 10
Solved Threads: 2