Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void loginBTNActionPerformed(java.awt.event.ActionEvent evt) {
- String s1 = userTF.getText();
- String s2 = passTF.getText();
- boolean isEmpty = false;
- boolean isUserExist = false;
- if(s1.equals("") || s2.equals("")){
- isEmpty = true;
- JOptionPane.showMessageDialog(null, "All fields are mandatory");
- }
- if(!isEmpty){
- try{
- Class.forName("java.sql.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "root", "lego");
- Statement st = con.createStatement();
- String studentlogin = "Select * from student where user ='"+s1+"';";
- ResultSet rs = st.executeQuery(studentlogin);
- while(rs.next()){
- isUserExist = true;
- String user=rs.getString("user");
- String pass=rs.getString("pass");
- if(s1.equals(user) && s2.equals(pass)){
- System.out.println("Login Successful");
- studentHomePage s = new studentHomePage(user);
- st.close();
- con.close();
- s.setVisible(true);
- this.dispose();
- break;
- } else {
- JOptionPane.showMessageDialog(null, "Password incorrect");
- }
- }
- if(!isUserExist){
- JOptionPane.showMessageDialog(null, "Username does not exist");
- }
- } catch(Exception e){
- System.out.println(e);
- }
- }
- }
Add Comment
Please, Sign In to add comment