title: checking duplicate for more than two values, if no such duplicate then insert query
body: <p><strong>Note:</strong> </p>
  
  <p><em>I have two <strong>columns</strong> (<strong>Name</strong>(primary key), <strong>Email</strong>(primary key))</em></p>
  
  <p>I have inserted <strong>two rows</strong>. </p>
  
  <p>The 1st row, where <code>name=ema</code> <code>email=ema@gmail.com</code>, and my 2nd row where <code>name=ena</code> <code>email=fe</code>. </p>
  
  <p>Now, when I want to insert a new record it only checks with the 1st row and the checking works, but if I want to insert <code>name=ena</code> and <code>email=something</code> it does not check for the second row. Can someone please suggest to me how do I overcome this?</p>
  
  <pre><code>try
          {
          Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/testing","root","");
  
      //block of code to check user exists or not.
      //Statement statement = connection.createStatement();
      PreparedStatement Pstatement;
  
      String query = "select Name,Email from detail";
      PreparedStatement ps = connection.prepareStatement(query);
      ResultSet rs = ps.executeQuery() ;
  
  
      if(rs.next())
      {
          //from database
          String name_db1 = rs.getString("Name").trim(); //using trim removes all white spaces
          String email_db2 = rs.getString("Email").trim();
  
          //from user GUI
          String entered_name = name.getText().trim(); //using trim removes all white spaces
          String entered_email = email.getText().trim();
  
          boolean valid = true;
  
          if(entered_name.equals(""))
          {
              JOptionPane.showMessageDialog(null,"Enter name");
              valid = false;
          }
          else if(name_db1.equals(entered_name))
          {
              JOptionPane.showMessageDialog(null,"Enter name taken");
              name.setText(null);
              valid = false;
          }
          else if(entered_email.equals(""))
          {
              JOptionPane.showMessageDialog(null,"Enter email");
              valid = false;
          }
          else if(email_db2.equals(entered_email))
          {
              JOptionPane.showMessageDialog(null,"email taken");
              email.setText(null);
              valid = false;
          }
          else if(valid == true)
          {
              Pstatement=connection.prepareStatement("insert into detail values(?,?)");
  
              //Specifying the values of preparestatement parameter                  
              Pstatement.setString(1,name.getText());
              Pstatement.setString(2,email.getText());
              Pstatement.executeUpdate();
              JOptionPane.showMessageDialog(null,"registration successful");  
              //x++;
          }
  
      }
      else
      {
          //incase if the user click without filling up the fields
          JOptionPane.showMessageDialog(null,"not yet registered"); 
      }
      }
      catch(SQLException e)
      {
          e.printStackTrace();
      }
  </code></pre>