0

How to fix the java.lang.NullPointerException in this code using Eclipse 2019-12, java 8, spring boot and mysql?

In the repository:

public List<User> findByFirstNameAndName(String fname, String name) {

        String sql = "SELECT Prenom Nom FROM electeur WHERE Prenom = ? AND Nom = ?"; 
        List<User> users = jdbcTemplate.query(
                sql,
                new UserRowMapper());

        return users;

    }

In the controller:

BindingResult result;
JDBCTemplate userJDBC;    
List<User> exist = userJDBC.findByFirstNameAndName(user.getFirstName(), user.getName());            

             if (exist != null) {
                 result.reject("User exists already");
             }

             else
                return createUser(user);
        }

The code is for finding in the database if the first name and name exist already before creating a new user, and the line that causes the exception is:

List<User> exist = userJDBC.findByFirstNameAndName(user.getFirstName(), user.getName());
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

0 Answers0