Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SuppressWarnings("empty-statement")
- private void regelfogadActionPerformed(java.awt.event.ActionEvent evt) {
- String username = tf2.getText();
- String password = String.valueOf(pf1.getText());
- String pwism = String.valueOf(pf2.getText());
- String email = tf3.getText();
- boolean status = validate.validateEmail(email);
- boolean valid = true;
- if (!username.equals("")) {
- felhell.setText(null);
- } else {
- felhell.setText("Felhasználónév hiányzik!");
- valid = false;
- }
- if ((password.equals("")) || ((password.length() <= 8))) {
- pwell.setText("Jelszó nem megfelelő vagy üres!");
- valid = false;
- } else {
- if (pwism.equals("")) {
- pwell.setText(null);
- jelism.setText("Kérlek ismételd meg a jelszót!");
- valid = false;
- } else if (!password.equals(pwism)) {
- pwell.setText("A jelszavak nem egyeznek!");
- jelism.setText("A jelszavak nem egyeznek!");
- valid = false;
- } else {
- pwell.setText(null);
- jelism.setText(null);
- }
- }
- if (!status || email.equals(""))//regex
- {
- emailell.setText("Az email formátuma nem megfelelő vagy üres!");
- valid = false;
- } else {
- emailell.setText(null);
- }
- if (valid) {
- try {
- //Connection con= null;
- PreparedStatement pstmt = null;
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn;
- conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/logtest?zeroDateTimeBehavior=convertToNull", "root", "");
- pstmt = conn.prepareStatement("Insert into users (username,password,email)value (?,?,?)");
- pstmt.setString(1, username);
- pstmt.setString(2, password);
- pstmt.setString(3, email); //adatbázis kapcsolat
- int i = pstmt.executeUpdate();
- if (i > 0) {
- fullell.setText("Az adatok elmentve,most már beléphet!");
- fullell.setForeground(Color.green);
- tf2.setText(null);
- tf3.setText(null);
- pf1.setText(null);
- pf2.setText(null);
- }
- } catch (com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e) {
- fullell.setText("Ez a felhasználónév vagy email-cím már regisztrálva van!");
- } catch (HeadlessException | ClassNotFoundException | SQLException e) {
- JOptionPane.showMessageDialog(null, e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement