-
Notifications
You must be signed in to change notification settings - Fork 0
/
Regisrtation.java
66 lines (55 loc) · 2.24 KB
/
Regisrtation.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
package com.jsp.booking;
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("/Registration")
public class Regisrtation extends GenericServlet {
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
// TODO Auto-generated method stub
String username = req.getParameter("username");
String useremail = req.getParameter("useremailid");
String usermobile = req.getParameter("usermobilenumber");
String userpassword = req.getParameter("userpassword");
String useraddress = req.getParameter("useraddress");
String userid = req.getParameter("userid");
String insert = "insert into user_information(User_Name, Email_id,Mobile_number,Password, Address,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, usermobile);
ps.setString(4, userpassword);
ps.setString(5, useraddress);
ps.setString(6, userid);
int update = ps.executeUpdate();
PrintWriter pw = res.getWriter();
res.setContentType("text/html");
if (update != 0) {
//pw.println("<center><h1>Registration Successfull</h1></center>");
RequestDispatcher rd=req.getRequestDispatcher("Login.html");
rd.forward(req, res);
} else {
RequestDispatcher rd=req.getRequestDispatcher("Registration.html");
rd.include(req, res);
pw.println("<center><h1> Invalid Details</h1></center>");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}