User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 429,970 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,577 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 4124 | Replies: 7
Reply
Join Date: Mar 2007
Posts: 2
Reputation: sanju21 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sanju21 sanju21 is offline Offline
Newbie Poster

null check of resultset

  #1  
Mar 30th, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: null check of resultset

  #2  
Apr 2nd, 2007
tough luck.
This has nothing to do with JSP so don't expect an answer here.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: null check of resultset

  #3  
Apr 6th, 2007
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,
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: null check of resultset

  #4  
Apr 6th, 2007
scriptlets should NEVER be used, period.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: null check of resultset

  #5  
Apr 7th, 2007
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 12:50 am. Reason: correctness
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: null check of resultset

  #6  
Apr 7th, 2007
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: null check of resultset

  #7  
Apr 8th, 2007
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.
Reply With Quote  
Join Date: Sep 2007
Posts: 1
Reputation: webarch is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
webarch webarch is offline Offline
Newbie Poster

Re: null check of resultset

  #8  
Sep 27th, 2007
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 11:51 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC