|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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 ... |
|
#2
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Checking existence of a variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|