import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@ManagedBean
@RequestScoped
public class RegistrationBean {
private String firstName;
private String lastName;
private String email;
private String password;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String register() {
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "username", "password");
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO users (first_name, last_name, email, password) VALUES (?,?,?,?)");
pstmt.setString(1, firstName);
pstmt.setString(2, lastName);
pstmt.setString(3, email);
pstmt.setString(4, password);
pstmt.executeUpdate();
conn.close();
return "success";
} catch (SQLException e) {
return "error";
}
}
}
aW1wb3J0IGphdmF4LmZhY2VzLmJlYW4uTWFuYWdlZEJlYW47CmltcG9ydCBqYXZheC5mYWNlcy5iZWFuLlJlcXVlc3RTY29wZWQ7CmltcG9ydCBqYXZhLnNxbC5Db25uZWN0aW9uOwppbXBvcnQgamF2YS5zcWwuRHJpdmVyTWFuYWdlcjsKaW1wb3J0IGphdmEuc3FsLlByZXBhcmVkU3RhdGVtZW50OwppbXBvcnQgamF2YS5zcWwuU1FMRXhjZXB0aW9uOwoKQE1hbmFnZWRCZWFuCkBSZXF1ZXN0U2NvcGVkCnB1YmxpYyBjbGFzcyBSZWdpc3RyYXRpb25CZWFuIHsKICBwcml2YXRlIFN0cmluZyBmaXJzdE5hbWU7CiAgcHJpdmF0ZSBTdHJpbmcgbGFzdE5hbWU7CiAgcHJpdmF0ZSBTdHJpbmcgZW1haWw7CiAgcHJpdmF0ZSBTdHJpbmcgcGFzc3dvcmQ7CgogIHB1YmxpYyBTdHJpbmcgZ2V0Rmlyc3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