Guest User

Untitled

a guest
Dec 1st, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1.  private void loginBTNActionPerformed(java.awt.event.ActionEvent evt) {                                        
  2.        
  3.         String s1 = userTF.getText();
  4.         String s2 = passTF.getText();
  5.         boolean isEmpty = false;
  6.         boolean isUserExist = false;
  7.        
  8.         if(s1.equals("") || s2.equals("")){
  9.             isEmpty = true;
  10.             JOptionPane.showMessageDialog(null, "All fields are mandatory");
  11.            
  12.         }
  13.        
  14.         if(!isEmpty){
  15.         try{
  16.             Class.forName("java.sql.Driver");
  17.             Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "root", "lego");
  18.             Statement st = con.createStatement();
  19.            
  20.             String studentlogin = "Select * from student where user ='"+s1+"';";
  21.             ResultSet rs = st.executeQuery(studentlogin);
  22.            
  23.            
  24.            
  25.             while(rs.next()){
  26.                 isUserExist = true;
  27.                 String user=rs.getString("user");
  28.                 String pass=rs.getString("pass");
  29.                
  30.                 if(s1.equals(user) && s2.equals(pass)){
  31.                     System.out.println("Login Successful");
  32.                     studentHomePage s = new studentHomePage(user);
  33.                     st.close();
  34.                     con.close();
  35.                     s.setVisible(true);
  36.                     this.dispose();
  37.                    
  38.                     break;
  39.                 } else {
  40.                    
  41.                    JOptionPane.showMessageDialog(null, "Password incorrect");
  42.                    
  43.                 }
  44.                
  45.             }
  46.            
  47.             if(!isUserExist){
  48.                 JOptionPane.showMessageDialog(null, "Username does not exist");
  49.             }
  50.            
  51.            
  52.         } catch(Exception e){
  53.             System.out.println(e);
  54.         }
  55.        
  56.         }
  57.     }
Add Comment
Please, Sign In to add comment