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.

tough luck.
This has nothing to do with JSP so don't expect an answer here.

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,

scriptlets should NEVER be used, period.

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,

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.

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.

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.