Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  2. throws ServletException, IOException {
  3. response.setContentType("text/html;charset=UTF-8");
  4. String process = (String) request.getParameter("process");
  5. String name = (String) request.getParameter("process");
  6. String phone=(String) request.getParameter("phone");
  7. String email = (String) request.getParameter("email");
  8. String pwd = (String) request.getParameter("pwd");
  9. PrintWriter out = response.getWriter();
  10. out.println("Hello");
  11. signup(out,process,name,email,phone,pwd);
  12.  
  13. }
  14.  
  15. private static int signup(PrintWriter out,String process,String name,String email,String phone,String pwd){
  16. Connection con = null;
  17. PreparedStatement stmt = null;
  18. ResultSet rs = null;
  19. try {
  20. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/wine", "root", "");
  21.  
  22.  
  23. out.println("Process Not Found");
  24. if (process == "signup") {
  25.  
  26. String query = "INSERT INTO user(name,phone,email,password,role) VALUES(?,?,?,?,1)";
  27. stmt = con.prepareStatement(query);
  28. stmt.setString(1, name);
  29. stmt.setString(2, phone);
  30. stmt.setString(3, email);
  31. stmt.setString(4, pwd);
  32.  
  33. stmt.execute();
  34.  
  35. } else {
  36. out.println("Process Not Found");
  37. }
  38. } catch (SQLException e) {
  39. // do something appropriate with the exception, *at least*:
  40.  
  41. out.println(e);
  42. e.printStackTrace();
  43. return 0;
  44. }
  45. return 1;
  46. }
  47.  
  48. public static void main(String[] args) {
  49.  
  50. Connection con = null;
  51. PreparedStatement stmt = null;
  52. ResultSet rs = null;
  53. String process = "signup";
  54. String name = "Test";
  55. String phone="45885";
  56. String email = "Test@gmail.com";
  57. String pwd = "dkjsdh";
  58.  
  59. try {
  60. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/wine", "root", "");
  61.  
  62.  
  63.  
  64. if (process == "signup") {
  65.  
  66. String query = "INSERT INTO user(name,phone,email,password,role,status) VALUES(?,?,?,?,1,1)";
  67. stmt = con.prepareStatement(query);
  68. stmt.setString(1, name);
  69. stmt.setString(2, phone);
  70. stmt.setString(3, email);
  71. stmt.setString(4, pwd);
  72.  
  73. stmt.execute();
  74.  
  75. } else {
  76. System.out.println("Process Not Found");
  77. }
  78. } catch (SQLException e) {
  79. // do something appropriate with the exception, *at least*:
  80.  
  81. System.out.println(e);
  82. e.printStackTrace();
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement