how to handle null pointer exception in ejb3

hi

its very silly question i dont know how to check the object is null or not.

this is my code snippet,

Query query=em.createQuery("select u from Users u where u.firstname = :username and u.password = :password");

query.setParameter("username",username);

query.setParameter("password",passwd);

Users user=(Users)query.getSingleResult();

return user;

}

suppose if the constraints not satisfied,user object will be null.

but how to check that one,i tried this way if(user!=null)

but didnt work..

please help me

regards

shru

[616 byte] By [patel123a] at [2007-11-27 7:40:50]
# 1

> hi

> its very silly question i dont know how to check the

> object is null or not.

> this is my code snippet,

>

> Query query=em.createQuery("select u from Users u

> where u.firstname = :username and u.password =

> :password");

> query.setParameter("username",username);

> query.setParameter("password",passwd);

> Users user=(Users)query.getSingleResult();

>return user;

> }

>

>

> suppose if the constraints not satisfied,user object

> will be null.

>

> but how to check that one,i tried this way

> if(user!=null)

>

> but didnt work..

> please help me

>

> regards

> shru

if (user != null)

is the correct way. i.e Testing if user is not null

r035198xa at 2007-7-12 19:21:23 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...