Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old August 14th, 2002, 10:56 PM
jagerkiss jagerkiss is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Location: Yogyakarta, Indonesia
Posts: 22 jagerkiss User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Checking existence of a variable

Hi all!

I always find difficulties when I build a form to do some searching. I mean the form which send all variables to itself. For the first time it runs, of course the variables (which are needed by the database query) are empty. And always this makes errors.

So, what can I do to check whether a variable is empty or not?

I've tried to make an if-clause to check this, but if I put the query inside the if-clause, the query result would not recognized outside the if-brackets. If I put the query outside the if-clause, this would make an error message.

Example:

Code:
a=request.getParameter("a");

if(a!=null) {
 ... running query ... 
}

...
...
...

//getting values from query result

<jsp: ....>


In this case, error message would come from getting the values of query result.

Any help, please ...

Reply With Quote
  #2  
Old August 14th, 2002, 11:56 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
You declare the ResultSet before you actually run the query, before the if clause. Then you assign the results of the query the to the ResultSet inside the if clause.
Alternately, make the if clause a lot longer. There's really no reason to access the data from the query outside of the if clause, since the ResultSet might be empty.
Btw, in case you didn't know, you can close a block of java code (%>) while you're still inside an if block, do some html stuff, then go back into java (<%) to close the if block.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Checking existence of a variable


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway