1. No Profile Picture
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Yogyakarta, Indonesia
    Rep Power

    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.


    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 ...
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Sacramento, CA
    Rep Power
    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.

IMN logo majestic logo threadwatch logo seochat tools logo