All you have to do is return an empty object - say, a client record that you would have in your DAO, for example,
if (result == null) {return new EmptyUser (); }
where EmptyUser extends the User and returns the appropriate entries in getter calls to let the rest of your code know that this is an empty object (id = -1, etc.)
A small example
public class User { private int id; private String name; private String gender; public String getName() { //Code here } public void setName() { //Code here } } public class EmptyUser extends User { public int getId() { return -1; } public String getName() { return String.Empty(); } } public User getEntry() { User result = db.query("select from users where id = 1"); if(result == null) { return new EmptyUser(); } else { return result; } }
source share