code: public <T> Optional<T> queryForOptionalObject(String sql, Map<String, ?> paramMap, Class<T> requiredType) throws DataAccessException {
          Optional<T> result;
  
          try {
              final T obj = super.queryForObject(sql, paramMap, requiredType);
              result = Optional.ofNullable(obj);
          } catch (EmptyResultDataAccessException e) {
              result = Optional.empty();
          }
  
          return result;
      }
docs: Query given SQL to create a prepared statement from SQL and a
  list of arguments to bind to the query, expecting a result object.
  <p>The query is expected to be a single row/single column query; the returned
  result will be directly mapped to the corresponding object type.
  @param sql SQL query to execute
  @param paramMap map of parameters to bind to the query
  (leaving it to the PreparedStatement to guess the corresponding SQL type)
  @param requiredType the type that the result object is expected to match
  @param <T> The return object type
  @return the result object of the required type (optionally)
  @throws org.springframework.dao.EmptyResultDataAccessException
  if the query does not return exactly one row, or does not return exactly
  one column in that row
  @throws org.springframework.dao.DataAccessException if the query fails
  @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)