August 14th, 2002, 11:56 PM
Checking existence of a variable
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.
In this case, error message would come from getting the values of query result.
... running query ...
//getting values from query result
Any help, please ...
August 15th, 2002, 12:56 AM
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.