dcsimg
Problems with != null and == null
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ugo_Orellana
Posted On:   Sunday, December 1, 2002 08:17 PM

I created a script with the following structure: rs = s.executeQuery("select * from TableName") if (rs.next()== true) { if ((rs.getString(column1) != null) and (rs.getString(column2) == null)) do something } When I execute it, it can't compile (!= null) and (== null). I also tryed using: if ((rs.getString(column1) is not null) and (rs.getString(column2) is null)) But it doesn't work also. Can someone help me on how to make an if... statement to determine if the resultset getString is null or not. Thank you for your help    More>>

I created a script with the following structure:


rs = s.executeQuery("select * from TableName")

if (rs.next()== true)

{

if ((rs.getString(column1) != null) and (rs.getString(column2) == null))

do something

}


When I execute it, it can't compile (!= null) and (== null).

I also tryed using:


if ((rs.getString(column1) is not null) and (rs.getString(column2) is null))


But it doesn't work also.

Can someone help me on how to make an if... statement to determine if the resultset getString is null or not.

Thank you for your help

   <<Less

Re: Problems with != null and == null

Posted By:   Anonymous  
Posted On:   Tuesday, December 10, 2002 08:25 AM

For reasons I don't understand, it is easier to test for nulls in databeans, and then force the return of whatever data you want in a getter. I had a stupid situation where I was testing for a voluntary field. The test was if there is nothing in the field, do nothing. However, bloody database kept throwing back the word (I guess) "null", triggering the validation. I could not capture this on the JSP page (I gather you can't test for the word "null"), but could in a getter. For example:



public java.lang.String getAword() {
if(aword == null || aword.length() <1){
return "";}
else {
return aword;
}
}


The solution (and I gather good practice) was to first load all the infortmation from the database into a databean, and then load the form from the databean.

Re: Problems with != null and == null

Posted By:   Dana_A  
Posted On:   Tuesday, December 3, 2002 02:14 PM

it should just be


if (rs.next())

not
rs.next() == true

because what you were doing was redundant...



and you should use && not and or & because && is for boolean and, & is for bitwise and. Similarly || is boolean or, | is bitwise. That's C syntax really, java is full of C syntax...

Re: Problems with != null and == null

Posted By:   Edison_Wong  
Posted On:   Monday, December 2, 2002 08:59 PM

I think you should try to change your codes as below:

if (rs.getString(column1) != null && rs.getString(column2) == null)

Re: Problems with != null and == null

Posted By:   Joost_Schouten  
Posted On:   Sunday, December 1, 2002 09:23 PM

Try this

if ((rs.getString(column1) != null) & (rs.getString(column2) == null))

Watch out with checking database entries for null though. You'll find yourself runnign into problems with empty strings. This is a string without any characters in it, but it is not null.


by the way, this is more a javalanguage question than a jsp.


Good luck,

joost

About | Sitemap | Contact