title: I don't konw what is wrong with my result set in java
body: <p>I am new in java programing and I'm trying to understand why I'm having the error below:
  I have almost spent 6 hours and no luck, I have rebooted mysql server and my PC also the ip and port 
  are Ok. What's wrong with mt 'ResultSet'? Can some one help me with this please.</p>
  
  <p>Thanks in advance for your help.</p>
  
  <pre><code>button.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
  
                      char[] tempPass = password.getPassword();
                      typedPassword = new String(tempPass);
  
                      if (!username.getText().equals("") &amp;&amp; !typedPassword.equals("")) {
  
                          String sql = "SELECT id, username, password, admin FROM users where username=? and password=?";
                          try {
                              PreparedStatement statement = connection.prepareStatement(sql);
                              statement.setString(1, username.getText().toString());
                              statement.setString(2, typedPassword);
  
                              ResultSet set = statement.executeQuery();                   
                              String admin = set.getString("admin");
                              preferences.put("user_id", set.getString("id"));
  
                              int count = 0;
                              while (set.next()) {
                                  count++;
                              }
  
                              if (count == 1) {
                                  JOptionPane.showMessageDialog(button, "Login success");
  
                                  if (chckbxRememberMe.isSelected()) {
                                      DoLogin log = new DoLogin();
                                      log.execute();
                                  } else {
                                      DoDelete delete = new DoDelete();
                                      delete.execute();
                                  }
                                  if(admin.equals("1")){
                                      Login.this.hide();
                                      Admin frMain = new Admin();
                                      frMain.setVisible(true);
                                      frMain.show();
                                  }
                                  else {
                                      Login.this.hide();
                                      Customer frMain = new Customer();
                                      frMain.setVisible(true);
                                      frMain.show();
                                  }
  
                              } else if (count &gt; 1) {
                                  System.out.println("Duplicate");
                              } else {
                                  System.out.println("not Exists");
                              }
                          } catch (SQLException e1) {
                              e1.printStackTrace();
                          }
  
                      } else {
                          JOptionPane.showMessageDialog(panel, "Fields can not be empty");
                      } 
                  }
  
              });
  </code></pre>
  
  <p>Here is the Error :</p>
  
  <pre><code>java.sql.SQLException: Before start of result set
              at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
              at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
              at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
              at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
              at com.mysql.cj.jdbc.result.ResultSetImpl.checkRowPos(ResultSetImpl.java:484)
              at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:834)
              at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:852)
              at msm.Login$3.actionPerformed(Login.java:175)
              at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
              at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
              at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
              at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
              at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
              at java.awt.Component.processMouseEvent(Unknown Source)
              at javax.swing.JComponent.processMouseEvent(Unknown Source)
              at java.awt.Component.processEvent(Unknown Source)
              at java.awt.Container.processEvent(Unknown Source)
              at java.awt.Component.dispatchEventImpl(Unknown Source)
              at java.awt.Container.dispatchEventImpl(Unknown Source)
              at java.awt.Component.dispatchEvent(Unknown Source)
              at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
              at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
              at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
              at java.awt.Container.dispatchEventImpl(Unknown Source)
              at java.awt.Window.dispatchEventImpl(Unknown Source)
              at java.awt.Component.dispatchEvent(Unknown Source)
              at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
              at java.awt.EventQueue.access$500(Unknown Source)
              at java.awt.EventQueue$3.run(Unknown Source)
              at java.awt.EventQueue$3.run(Unknown Source)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
              at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
              at java.awt.EventQueue$4.run(Unknown Source)
              at java.awt.EventQueue$4.run(Unknown Source)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
              at java.awt.EventQueue.dispatchEvent(Unknown Source)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
              at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
              at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
              at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
              at java.awt.EventDispatchThread.run(Unknown Source)
  </code></pre>