-
Notifications
You must be signed in to change notification settings - Fork 0
/
Registration.java
70 lines (58 loc) · 2.38 KB
/
Registration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.jsp;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.GenericServlet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
@WebServlet("/userregistration")
public class Registration extends GenericServlet {
@Override
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String username = request.getParameter("username");
String useremail = request.getParameter("useremail");
String userpassword = request.getParameter("userpassword");
String usermobile = request.getParameter("usermobile");
String usergender = request.getParameter("usergender");
String userdob = request.getParameter("userdob");
String usernum = request.getParameter("usernum");
String insert ="insert into bank_user_details(User_Name,User_Email_id,User_Password,User_Mobile_Number,User_Gender,User_Date_Of_Birth, User_id)"
+"values(?,?,?,?,?,?,?)";
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection= DriverManager.getConnection("jdbc:mysql://localhost:3306/advancejava?user=root&password=12345");
PreparedStatement ps =connection.prepareStatement(insert);
ps.setString(1, username);
ps.setString(2, useremail);
ps.setString(3, userpassword);
ps.setString(4, usermobile);
ps.setString(5, usergender);
ps.setDate(6, Date.valueOf(userdob));
ps.setString(7, usernum);
int update=ps.executeUpdate();
PrintWriter write = response.getWriter();
response.setContentType("text/html");
if(update!=0) {
//write.println("<center><h1>Registration Successfull...</center></h1>");
RequestDispatcher r=request.getRequestDispatcher("UserLogin.html");
r.forward(request, response);
}
else {
RequestDispatcher r=request.getRequestDispatcher("Registration.html");
r.include(request, response);
write.println("<center><h1>Invalid Details</center></h1>");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}