title: SQL Query - need to be able to return nothing if query is not successful
body: <p>I am working to populate a User Details page, and at the moment, I am logged in as null user and it keeps breaking because this query has to return something.
  I want to make it so that if it is empty, it will return ""; instead of breaking.</p>
  
  <p>I have a vague idea how to do this but I need help! The query definitely works when a user is logged in because I have tested the code, and it populates when there is a valid user.</p>
  
  <p>I think it should be something like:</p>
  
  <pre><code> @Override
          public UserDetails fetchUserById(int userId) {
              String query = "select ID, LOGIN_ID, EMAIL_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME, decode(is_primary, 1, 'true', 'false') IS_PRIMARY, decode(status, 1, 'true', 'false') IS_ACTIVE from user_details where ID = ?";
      List&lt;UserDetails&gt; strLst = return jdbcTemplate.queryForObject(query, new RowMapper&lt;UserDetails&gt;() {
  
                      @Override
                      public UserDetails mapRow(ResultSet rs, int rowNum) throws SQLException {
                          UserDetails userDetails = new UserDetails ();
                          userDetails .setId(rs.getInt("ID"));
                          userDetails .setIntranetId(rs.getString("LOGIN_ID"));
                          userDetails .setEmailId(rs.getString("EMAIL_ID"));
                          userDetails .setFirstName(rs.getString("FIRST_NAME"));
                          userDetails .setMiddleName(rs.getString("MIDDLE_NAME"));
                          userDetails .setLastName(rs.getString("LAST_NAME"));
     userDetails.setPrimaryAnalyst(Boolean.valueOf(rs.getString("IS_PRIMARY")));
                          userDetails.setStatus(Boolean.valueOf(rs.getString("IS_ACTIVE")));
                          return userDetails;
                  }
      }, userId);
  
      if (strLst.isEmpty()) {
          return " ";
      } else {
          return strLst.get(0);
  
      }
  }
  </code></pre>
  
  <p>This is my code for the query:</p>
  
  <pre><code> @Override
          public UserDetails fetchUserById(int userId) {
              String query = "select ID, LOGIN_ID, EMAIL_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME, decode(is_primary, 1, 'true', 'false') IS_PRIMARY, decode(status, 1, 'true', 'false') IS_ACTIVE from user_details where ID = ?";
                  RowMapper&lt;UserDetails&gt; rowMapper = new RowMapper&lt;UserDetails&gt;(){
  
                      @Override
                      public UserDetails mapRow(ResultSet rs, int rowNum) throws SQLException {
                          UserDetails userDetails = new UserDetails ();
                          userDetails .setId(rs.getInt("ID"));
                          userDetails .setIntranetId(rs.getString("LOGIN_ID"));
                          userDetails .setEmailId(rs.getString("EMAIL_ID"));
                          userDetails .setFirstName(rs.getString("FIRST_NAME"));
                          userDetails .setMiddleName(rs.getString("MIDDLE_NAME"));
                          userDetails .setLastName(rs.getString("LAST_NAME"));
     userDetails.setPrimaryAnalyst(Boolean.valueOf(rs.getString("IS_PRIMARY")));
                          userDetails.setStatus(Boolean.valueOf(rs.getString("IS_ACTIVE")));
                          return userDetails;
                  };
                  return jdbcTemplate.queryForObject(query, rowMapper, userId);
  
          }
  </code></pre>
  
  <p>The error for null user reads
  HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0</p>