944,078 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 17139
  • JSP RSS
Mar 30th, 2007
0

null check of resultset

Expand Post »
I have tried rs.wasNull() to check the null value from the database table..but it doesn't work.. pls let me show other ways to check null.. I consider the empty table when i request.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sanju21 is offline Offline
2 posts
since Mar 2007
Apr 2nd, 2007
0

Re: null check of resultset

tough luck.
This has nothing to do with JSP so don't expect an answer here.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Apr 6th, 2007
0

Re: null check of resultset

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,
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
rgtaylor is offline Offline
83 posts
since Mar 2007
Apr 6th, 2007
0

Re: null check of resultset

scriptlets should NEVER be used, period.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Apr 7th, 2007
0

Re: null check of resultset

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,
Last edited by rgtaylor; Apr 7th, 2007 at 1:50 am. Reason: correctness
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
rgtaylor is offline Offline
83 posts
since Mar 2007
Apr 7th, 2007
0

Re: null check of resultset

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Apr 8th, 2007
0

Re: null check of resultset

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.
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
rgtaylor is offline Offline
83 posts
since Mar 2007
Sep 27th, 2007
0

Re: null check of resultset

jwenting, I doubt you are really concerned about "kids" learning to write code well. If you were, you wouldn't be so condescending and inflammatory in your tone. Especially as a moderator, you should be ashamed. I note that rgtaylor was banned after this posting, although he was much cooler-headed about responding to your a$$holishness than I could ever be.

Sure, scriptlets are bad in the first place, but you did a really awful job of making that point here, if that was truly your intent, which I doubt, since you seemed so much more focused on being a jerk to the two other people who were asking for help and trying to be constructive. I feel bad for sanju21... and rgtaylor... and most of all you. Change your tone, and maybe people will listen.

And 7 years of JSP development? That ain't nothin'. I once lifted a 3 lb. weight over my head; good for me.

You'll probably ban me now, too. Awesome.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
webarch is offline Offline
1 posts
since Sep 2007
Nov 18th, 2010
0
Re: null check of resultset
thanks for the post rgtaylor

I accidentally used .equals to check a resultset instead of ==

rs.getString(1).equals(null) vs rs.getString(1) == null

mine is pure java, but concept is the same
Reputation Points: 10
Solved Threads: 0
Newbie Poster
toughlittleone is offline Offline
2 posts
since Mar 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in JSP Forum Timeline: help with database
Next Thread in JSP Forum Timeline: Problem facing for old session in a JSP page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC