November 21, 2002

JSP Null Queries Update

Okay. I was wrong in my earlier post.


if ( rs.first() == false ) {....}

That will check for a null query.

Okay. But now for the goofy part. This will move the recordset from BEFORE the First Record to the First Record. Make sense? So now, when you do your while rs.next(), it will start where? The SECOND record.

Solution: put rs.beforeFirst(); BEFORE your while rs.next() and it will start right back at the beginning.

It was incredibly painful to find this simple information. Why Java doesn’t have a RecordSet.Count or something along those lines, I just do not know. It’s stupid. That’s right. STUPID. You simply have to be easily be able to check for null queries. How else can you have dynamic, database-driven sites with conditional logic?

Thanks to Nash Foster for the help in figuring this out. He dug up the information that was freaking buried at the Java Sun Site.

Post Info

Tagged As Coding, Java Server Pages

Comments are Open (1)

Posted at 12:00 PM

Comments

some student

Thank you for this incredible info, I have been staring in frustration at some JSP code i've been writingfor the past ... 5 hours, wondering why i can't find any way to evaluate whether my SQL query was returning null or not... And now I have a way to do it. I agree, it's incredibly STUPID that there is no simpler way to do it.

Thanks very much for the info.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Search
Comments on this post
Categories
Info
Tony Stephens
Copyright © 1995-2005
Site Version:
10
Licensed:
Creative Commons
Validate:
XHTML, CSS, 508, RSS
Subscribe
Blog-Fu, Link-Fu