wood burning stoves 2.0*
The moose likes JSP and the fly likes Set to null... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Set to null..." Watch "Set to null..." New topic
Author

Set to null...

George Larry
Ranch Hand

Joined: Nov 07, 2001
Posts: 52
I have a problem...
I'm working with JSP and PL/SQL procedures.
I have a form where users are able to enter text that will be used in a search. I've written a procedure to run the search, but some of the fields are optional so I use the NVL(x,y) function.
Basically what that does is check to see if the value is null and uses 'y' if it is, and 'x' if it is not.
So... What I need to do is be sure that when I call this procedure the value is either something the user entered... or null.
The problem is- instead of getting NULL when the user doesn't enter anything- I'm getting "". How can I make a variable be NULL?
I thought that I could do a check- like this:
if ( myVar.equals( "" ) ) myVar = null;
But that doesn't seem to be working.
Is there something I can do in my entry form? Is there some way to force a variable to be null?
Thanks in advance.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You probably need to trim it. Try this...
if (myVar.trim().equals(""))


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
George Larry
Ranch Hand

Joined: Nov 07, 2001
Posts: 52
I don't think that's the problem. I already checked the value of the variable and- when the user doesn't enter anything myVar = "". When I try to set the variable to null...
myVar = null;
...it becomes the string "null" it doesn't become null. So when I send it to my procedure it searches for the value "null"... I need to send it NULL.
Any more ideas?
V Srinivasan
Ranch Hand

Joined: Aug 16, 2000
Posts: 99
I think instead of checking the variable with "" try to find the length, if it is 0 set myVar to null.
Mahesh Mamani
Ranch Hand

Joined: Jun 25, 2001
Posts: 110
Hi,
U can try this function also:
// ----------------------------------------------------------------------------
// Purpose: Check if input is a empty string
// Parameters: szStr - value to be checked
// Return: returns false if not blank else
// return true
// ----------------------------------------------------------------------------
function bCheckBlank(szStr)
{
for(var i = 0; i < szStr.length; i++) {
var c = szStr.charAt(i);
if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
}
return true;
}


Mahesh
[ April 25, 2002: Message edited by: Mahesh Mamani ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set to null...