title: How to get single record from database using email address
body: <p>We have a Register Form data in database and now i have to get single record related email which is entered in another login jsp page POJO class.</p>
  
  <p>I developed application for register form and his data to store into database.so i am creating bellow classes.</p>
  
  <p>Here how to develop code in Dao Implementation getDataByUsingEmail method for getting the single record from database.</p>
  
  <p>here another pojo class also there ...so i am reading email address from there i want.</p>
  
  <p>Controller Class:</p>
  
  <pre><code> package com.spring.form;
  
      import java.io.FileInputStream;
      import java.io.IOException;
      import java.io.PrintWriter;
      import java.util.ArrayList;
      import java.util.HashMap;
      import java.util.List;
  
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.stereotype.Controller; 
      import org.springframework.ui.Model;
      import org.springframework.ui.ModelMap;
      import org.springframework.web.bind.annotation.ModelAttribute;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestMethod;
      import org.springframework.web.bind.annotation.RequestParam;
      import org.springframework.web.bind.annotation.ResponseBody;
      import org.springframework.web.servlet.ModelAndView;
  
      import com.spring.model.FormData;
      import com.spring.model.LoginData;
      import com.spring.services.FormDataService;
  
      import javax.servlet.http.HttpServletResponse;
  
  
      @Controller
      public class FrontController
      {
          @Autowired
          private FormDataService formDataService;
  
  
          HashMap&lt;String, String&gt; map=new HashMap&lt;String, String&gt;();
  
  
          @RequestMapping(value="/loginAndGetData",method=RequestMethod.POST)
          public String getFormDataByEmail(Model model,LoginData loginData) 
          {
              String emailId=loginData.getLoginEmail();
  
              System.out.println("Email entered is : "+loginData.getLoginEmail());
  
              model.addAttribute("formData", new FormData());
              model.addAttribute("listFormData", formDataService.getFormDataByEmail(emailId));
  
              return "result";
  
          }
  }
  </code></pre>
  
  <p>Model Class:</p>
  
  <pre><code>package com.spring.model;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="mdm_registration_form", schema="MDMS")
  public class FormData 
  {
      @Id
      @Column(name="email")
      private String email;
  
      @Column(name="Fname")
      private String Fname;
  
      @Column(name="Lname")
      private String Lname;
  
      @Column(name="mobile")
      private String mobile;
  
      @Column(name="gend")
      private String gend;
  
      @Column(name="marry")
      private String marry;
  
      @Column(name="dob")
      private String dob;
  
      @Column(name="password")
      private String password;
  
      @Column(name="address")
      private String address;
  
      @Column(name="country")
      private String country;
  
      @Column(name="idcard")
      private String idcard;
  
      @Column(name="idupload")
      private String idupload;
  
      @Column(name="addid")
      private String addid;
  
      @Column(name="adupload")
      private String adupload;
  
  
  
      public FormData(){
  
      }
  
      public String getFname() {
          return Fname;
      }
      public void setFname(String fname) {
          Fname = fname;
      }
  
      public String getLname() {
          return Lname;
      }
  
      public void setLname(String lname) {
          Lname = lname;
      }
  
      public String getMobile() {
          return mobile;
      }
  
      public void setMobile(String mobile) {
          this.mobile = mobile;
      }
  
      public String getGend() {
          return gend;
      }
  
      public void setGend(String gend) {
          this.gend = gend;
      }
  
      public String getMarry() {
          return marry;
      }
  
      public void setMarry(String marry) {
          this.marry = marry;
      }
  
      public String getDob() {
          return dob;
      }
  
      public void setDob(String dob) {
          this.dob = dob;
      }
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public String getAddress() {
          return address;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  
      public String getCountry() {
          return country;
      }
  
      public void setCountry(String country) {
          this.country = country;
      }
  
      public String getIdcard() {
          return idcard;
      }
  
      public void setIdcard(String idcard) {
          this.idcard = idcard;
      }
  
      public String getAddid() {
          return addid;
      }
  
      public void setAddid(String addid) {
          this.addid = addid;
      }
  
      public String getIdupload() {
          return idupload;
      }
  
      public void setIdupload(String idupload) {
          this.idupload = idupload;
      }
  
      public String getAdupload() {
          return adupload;
      }
  
      public void setAdupload(String adupload) {
          this.adupload = adupload;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
  
  }
  </code></pre>
  
  <p>Dao Implementation:</p>
  
  <pre><code>package com.spring.dao;
  
  import java.util.List;
  
  import javax.persistence.Query;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.orm.hibernate5.HibernateTemplate;
  import org.springframework.stereotype.Repository;
  
  import com.spring.model.FormData;
  import com.spring.model.LoginData;
  
  
  @Repository
  
  public class FormDaoImpl implements FormDao
  {
  
      @Autowired
      private SessionFactory sessionFactory;
  
  
  
      @Override
      public FormData getFormDataByEmail(String emailId) 
      {
          /*
          FormData formData= null;
          Session session = this.sessionFactory.getCurrentSession();
          Query query= null;
          String passedquery="select * from MDMS.mdm_registration_form where email='"+emailId+"'";
          formData= session.get(FormData.class, emailId);
          return formData; */
  
          Session session = this.sessionFactory.getCurrentSession();
  
          String hql = "FROM FormData formData WHERE formData.email ="+emailId;
  
          Query query = session.createQuery(hql);
  
          //List results = query;
  
          return formData;
      }
  </code></pre>
  
  <p>Service Implementation</p>
  
  <pre><code>import java.util.List;
  
  import javax.transaction.Transactional;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import com.spring.dao.FormDao;
  import com.spring.model.FormData;
  
  
  @Service
  public class FormDataServiceImpl implements FormDataService
  {
      @Autowired
      private FormDao formDao;
  
  
      @Override
      @Transactional
      public FormData getFormDataByEmail(String emailId)
      {
  
          return formDao.getFormDataByEmail(emailId);
      }
  }
  </code></pre>
  
  <p>LoginData Pojo class:</p>
  
  <pre><code>package com.spring.model;
  
  public class LoginData {
  
      private String loginEmail;
      private String loginPassword;
  
      public LoginData()
      {
  
      }
  
      public String getLoginEmail() {
          return loginEmail;
      }
  
      public void setLoginEmail(String loginEmail) {
          this.loginEmail = loginEmail;
      }
  
      public String getLoginPassword() {
          return loginPassword;
      }
  
      public void setLoginPassword(String loginPassword) {
          this.loginPassword = loginPassword;
      }
  
  
  }
  </code></pre>
  
  <p>Please suggest how to do that,
  Thanks in advance</p>