fork download
  1. import javax.faces.bean.ManagedBean;
  2. import javax.faces.bean.RequestScoped;
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7.  
  8. @ManagedBean
  9. @RequestScoped
  10. public class RegistrationBean {
  11. private String firstName;
  12. private String lastName;
  13. private String email;
  14. private String password;
  15.  
  16. public String getFirstName() {
  17. return firstName;
  18. }
  19.  
  20. public void setFirstName(String firstName) {
  21. this.firstName = firstName;
  22. }
  23.  
  24. public String getLastName() {
  25. return lastName;
  26. }
  27.  
  28. public void setLastName(String lastName) {
  29. this.lastName = lastName;
  30. }
  31.  
  32. public String getEmail() {
  33. return email;
  34. }
  35.  
  36. public void setEmail(String email) {
  37. this.email = email;
  38. }
  39.  
  40. public String getPassword() {
  41. return password;
  42. }
  43.  
  44. public void setPassword(String password) {
  45. this.password = password;
  46. }
  47.  
  48. public String register() {
  49. try {
  50. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "username", "password");
  51. PreparedStatement pstmt = conn.prepareStatement("INSERT INTO users (first_name, last_name, email, password) VALUES (?,?,?,?)");
  52. pstmt.setString(1, firstName);
  53. pstmt.setString(2, lastName);
  54. pstmt.setString(3, email);
  55. pstmt.setString(4, password);
  56. pstmt.executeUpdate();
  57. conn.close();
  58. return "success";
  59. } catch (SQLException e) {
  60. return "error";
  61. }
  62. }
  63. }
  64.  
  65.  
Success #stdin #stdout 0.01s 5264KB
stdin
Standard input is empty
stdout
�������