Pages

01 January 2013

[Java] Sample login button action

try {
            String sql="Select * from Users1";
            String host ="jdbc:derby://localhost:1527/Nash";
            String uName = "CON";
            String uPass = "smokes";
            Connection con = DriverManager.getConnection(host, uName, uPass);
            Statement stmt=con.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            String user= userName.getText();
            String pwd= password.getText();
            while(rs.next()) {
            String uname=rs.getString("User_name");
            String pass=rs.getString("Password");
            String admin1=rs.getString("admin");
            
    if ((user.equals(uname)) && (pwd.equals(pass)))
        { 
            if ((admin1.equals("y")))
            {  
                mainPanel.setVisible(true);
                blankContent.setVisible(true);
                adminButton.setEnabled(true);
                receiptContent.setVisible(false);
               memberContent.setVisible(false);
               securityPanel.setVisible(false); 
            }
            else 
            {
               mainPanel.setVisible(true);
               blankContent.setVisible(true);
               adminButton.setEnabled(false);
               receiptContent.setVisible(false);
               memberContent.setVisible(false);
               securityPanel.setVisible(false); 
            }
}
else
{
   JOptionPane.showMessageDialog(null,  "User name and password do"
   + " not match!","ALERT!", JOptionPane.ERROR_MESSAGE); 
                 
                }   
    }   } catch (SQLException ex) {
            Logger.getLogger(program.class.getName()).log(Level.SEVERE, null, ex);
        }

0 comments: