title: multi-user login java (admin,user,teacher)
body: <p>I have three user types in database.
      <a href="http://oi44.tinypic.com/2z8qflw.jpg" rel="nofollow">http://oi44.tinypic.com/2z8qflw.jpg</a></p>
  
  <p>And heres my login form
      <a href="http://oi44.tinypic.com/20p5v04.jpg" rel="nofollow">http://oi44.tinypic.com/20p5v04.jpg</a></p>
  
  <p>When i choose admin as usertype, enter the username and password from the database, the admin form shows up. But when i choose teacher and student, and type the username&amp;pass from the database, only the JOptionpane shows up which is the Invalid details.</p>
  
  <p>heres my code for login jframe:</p>
  
  <pre><code>JButton btnLogin = new JButton("Login");
  btnLogin.setFont(new Font("Book Antiqua", Font.PLAIN, 18));
  btnLogin.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {
      String sql = "SELECT * FROM useRecords ";
      try {
        ps = conn.prepareStatement(sql);
        rs=ps.executeQuery();
        String user = usern.getText();
        String pwd = new String (passw.getPassword());
        String type =(String)typeUser.getSelectedItem();
        while(rs.next()) { 
          String uname = rs.getString("username");
          String pass = rs.getString("password");
          if ((user.equals(uname)) &amp;&amp; (pwd.equals(pass))) { 
            if (type.equals("Admin")) {  // ... admin
              dispose();
              aCai aCai = new aCai();
              aCai.setVisible(true);
              aCai.setExtendedState(Frame.MAXIMIZED_BOTH);
            } else if (type.equals("Teacher")) {  // ... teacher
              dispose();
              tCai tCai = new tCai();
              tCai.setVisible(true);
              tCai.setExtendedState(Frame.MAXIMIZED_BOTH);
            } else {
              dispose();
              sCai sCai = new sCai();
              sCai.setVisible(true);
              sCai.setExtendedState(Frame.MAXIMIZED_BOTH);
            }
          } else {
            JOptionPane.showMessageDialog(null,  "User name and password do"
                                         + " not match!","ALERT!",
                                         JOptionPane.ERROR_MESSAGE); 
            break;
          }
        }
      } catch(Exception e) {
        JOptionPane.showMessageDialog(null, e);
      } finally {
        try{
          rs.close();
          ps.close();
        } catch(Exception e) {
        }
      }
    }
  });
  </code></pre>