Advertisement
Guest User

regjavit

a guest
Jun 10th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.87 KB | None | 0 0
  1. @SuppressWarnings("empty-statement")
  2.     private void regelfogadActionPerformed(java.awt.event.ActionEvent evt) {
  3.  
  4.  
  5.         String username = tf2.getText();
  6.         String password = String.valueOf(pf1.getText());
  7.         String pwism = String.valueOf(pf2.getText());
  8.         String email = tf3.getText();
  9.  
  10.  
  11.         boolean status = validate.validateEmail(email);
  12.  
  13.         boolean valid = true;
  14.  
  15.         if (!username.equals("")) {
  16.             felhell.setText(null);
  17.         } else {
  18.             felhell.setText("Felhasználónév hiányzik!");
  19.             valid = false;
  20.         }
  21.  
  22.         if ((password.equals("")) || ((password.length() <= 8))) {
  23.             pwell.setText("Jelszó nem megfelelő vagy üres!");
  24.             valid = false;
  25.         } else {
  26.             if (pwism.equals("")) {
  27.                 pwell.setText(null);
  28.                 jelism.setText("Kérlek ismételd meg a jelszót!");
  29.                 valid = false;
  30.             } else if (!password.equals(pwism)) {
  31.                 pwell.setText("A jelszavak nem egyeznek!");
  32.                 jelism.setText("A jelszavak nem egyeznek!");
  33.                 valid = false;
  34.             } else {
  35.                 pwell.setText(null);
  36.                 jelism.setText(null);
  37.             }
  38.         }
  39.  
  40.  
  41.         if (!status || email.equals(""))//regex
  42.         {
  43.             emailell.setText("Az email formátuma nem megfelelő vagy üres!");
  44.             valid = false;
  45.         } else {
  46.             emailell.setText(null);
  47.         }
  48.  
  49.         if (valid) {
  50.  
  51.             try {
  52.                 //Connection con= null;
  53.                 PreparedStatement pstmt = null;
  54.                 Class.forName("com.mysql.jdbc.Driver");
  55.                 Connection conn;
  56.                 conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/logtest?zeroDateTimeBehavior=convertToNull", "root", "");
  57.                 pstmt = conn.prepareStatement("Insert into users (username,password,email)value (?,?,?)");
  58.                 pstmt.setString(1, username);
  59.                 pstmt.setString(2, password);
  60.                 pstmt.setString(3, email);  //adatbázis kapcsolat
  61.                 int i = pstmt.executeUpdate();
  62.                 if (i > 0) {
  63.  
  64.                     fullell.setText("Az adatok elmentve,most már beléphet!");
  65.                     fullell.setForeground(Color.green);
  66.                     tf2.setText(null);
  67.                     tf3.setText(null);
  68.                     pf1.setText(null);
  69.                     pf2.setText(null);
  70.                 }
  71.             } catch (com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e) {
  72.                 fullell.setText("Ez a felhasználónév vagy email-cím már regisztrálva van!");
  73.             } catch (HeadlessException | ClassNotFoundException | SQLException e) {
  74.                 JOptionPane.showMessageDialog(null, e);
  75.             }
  76.         }
  77.  
  78.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement