Advertisement
Guest User

Untitled

a guest
Mar 7th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  2.        String passwordBefore= String.valueOf(passwordOO.getPassword());
  3.        String password = passwordBefore.trim();
  4.        String username = usernameOO.getText().trim();
  5.        if(password.length() <= 0 || username.length() <= 0){
  6.            JOptionPane.showMessageDialog(null, "Please fill the required text "
  7.                    + "fields in order to login!");
  8.        }else{
  9.        try{
  10.         int count = 0;
  11.         Connection myConn = DriverManager.getConnection("jdbc:mysql://frame.fpso.dk/javadb_dat2016", "java_guru", "tf58Nc?5");
  12.         Statement mySt = myConn.createStatement();
  13.         ResultSet myRS = mySt.executeQuery("SELECT username, password FROM users WHERE username='" + username + "'AND password='" + password+"'");
  14.         while (myRS.next()){
  15.         count++;
  16.         }
  17.        
  18.         if(count == 0){
  19.             JOptionPane.showMessageDialog(null, "Incorrect login, please try again");
  20.         }
  21.        
  22.         if(count == 1){
  23.             JOptionPane.showMessageDialog(null, "WELCOME " + username + " \n \n Successful Login");
  24.             LibraryWorker window = new LibraryWorker();
  25.             setVisible(false);
  26.             window.setVisible(true);
  27.         }
  28.     }catch(Exception ex){
  29.         System.out.println("Error:" + ex);
  30.     }
  31.        }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement