title: Java - How to fetch email address from phpMyAdmin and send using javamail
body: <p>I've designed <strong>ForgotMyPassword.java</strong> jFrame Form on NetBeans IDE 8.2
  wherein I'm using phpMyAdmin for fetching the E-Mail Address of registered users from it and sending it to their E-Mail Addresses through MYSQL Database using JavaMail</p>
  
  <p>I basically want to fetch the E-Mail Address of registered users from it and send it to their E-Mail Addresses through MYSQL Database using JavaMail as One Time Password (OTP) recovery option</p>
  
  <p>Here's the source code :</p>
  
  <pre><code>    String username = usrnmfield.getText();
      String email = emailID.getText();
      String[] to = {"emailaddr@gmail.com"};
  
      Connection conn=null;
      PreparedStatement pstn = null;
  
      try {
  
          Class.forName("com.mysql.jdbc.Driver");
  
          Connection db = DriverManager.getConnection("jdbc:mysql://localhost:3307/app" , "xxxx" , "xxxx");
          pstn=db.prepareStatement("select * from register where USERNAME=? and EMAIL=?");
  
          pstn.setString(1,username);
          pstn.setString(2,email);
  
          ResultSet i=pstn.executeQuery();
  
          if(i.next())
  
          {
  
  
      if(JavaMail.send
      ("abc@gmail.com", 
      "xxxx",
      to,
      "Hello world",
      "Thank you for reading my post"))
  
      {
  
          JOptionPane.showMessageDialog(null , " Please Check out your Inbox for any Password sent by us to you ");
  
          }
  
          }
  
          else if (usrnmfield != i &amp;&amp; emailID != i)
  
          {
  
             JOptionPane.showMessageDialog(null, "Wrong Username or E-Mail ID");
  
          }     
  
      } catch(HeadlessException | ClassNotFoundException | SQLException e) {
          JOptionPane.showMessageDialog(null, e);
  
      }
  
  
  }                                        
  </code></pre>