*
The moose likes JSP and the fly likes Null Arguement Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Null Arguement Question" Watch "Null Arguement Question" New topic
Author

Null Arguement Question

Bernard Bobinski
Greenhorn

Joined: Aug 30, 2004
Posts: 14
In a report called the Daily Bulletin I have a notification section. One of the fields is entitled NARRATIVE. If the rpdnotification table is empty, can I set the value of NARRITIVE to "None at this time" and have is display the same? I have tried several times but get no results. My code for that section is as follows.

TABLE rpdnotifiation
FIELDS are subject, authority, narrative, startdate, rundays, and rundays



Respectfully,<br /> <br />Bernard J. Bobinski
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

can I set the value of NARRITIVE to "None at this time" and have is display the same?


I have no idea what you are asking as NARRITIVE [sic] (or even NARRATIVE) does not appear anywhere in your code. Java is case sensitive, as you know. Are you talking about the db column? the scripting variable?

What are you trying to set?
[ September 08, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Note: when the table is empty, you get no results and your loop will never execute.

Btw, did I mention that doing SQL and dealing with result sets in a JSP page is evil? Best practice is to deal with this sort of stuff in a servlet and forward to a JSP page with a plain old collection containing your data for view.
Bernard Bobinski
Greenhorn

Joined: Aug 30, 2004
Posts: 14
Sorry - NARRATIVE refers to narrative. There is a lot more to this page than what is displayed. The actual page is over 600 lines long. I only posted the section I was having trouble with.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
How about changing:

Jules
Bernard Bobinski
Greenhorn

Joined: Aug 30, 2004
Posts: 14
Tried your code - the results are still negative. Question - Does it have something to do with the WHILE LOOP. Does the LOOP have to be broken to show desired results?
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
I can't see anything wrong with your JSP code, however your HTML sucks. You've got <tr> inside <td> without an enclosing <table> (I'm not talking about outside the while loop, I mean inside it)[Edit: actually that's not true; I just didn't spot it as it wasn't indented - apologies]. You've also got extra closing tags, e.g. </strong>. It's possible that the malformed HTML is not helping the situation. Perhaps it's worth checking that out. Meanwhile I'm just going to knock up a quick example.

Jules
[ September 09, 2004: Message edited by: Julian Kennedy ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

I'm confused about what has you confused. You have stated that the table is empty, and yet you seem to be surprised that that results in no data being displayed.

As I stated before, with an empty table you get a zero-length results set; therefore rs.next() returns false, therefore the body of your while loop never gets executed, therefore no output.

What am I not getting?
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
OK, this self-contained page, which basically incorporates your code, works perfectly for me (looks bloody awful, but works perfectly!):

The top part mimics a SQL ResultSet.

Now, after all that I think I may have completely missed the point which is, as Bear has said, that if you're not getting any results back then your loop will never be executed, your rows will never be created and you won't get any output beyond the static stuff. If you want to display "none at this time" when there are no results you'll need to check that after you've executed your query and display your message instead of doing the while loop.

Hope this helps.

Jules
Bernard Bobinski
Greenhorn

Joined: Aug 30, 2004
Posts: 14
Took your adive and solved the Null Argument Problem. I attacked the problem form a new angle and ended up successful. I used the following code.

bullNotificationTrue.jsp - Displays Query Results
bullNotificationFalse.jsp - Displays "None at this time"




Thanks again for the help
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Null Arguement Question
 
Similar Threads
JSP Help Regarding the Radio Button
inserting data to a table
Data Display problem in JSP.
Reference a Table Field Value in a SQL Statement using JSP
The Rookie Throws in the Towel (Kind of)