forked from Safnaj/Java-Web-Application
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateProcessUserHistory.java
More file actions
83 lines (66 loc) · 2.12 KB
/
updateProcessUserHistory.java
File metadata and controls
83 lines (66 loc) · 2.12 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
//-----------IT17045940
//-----------Dias A.M.A.P.
//-----------G-1.2
import java.sql.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/updateProcessUserHistory")
public class updateProcessUserHistory extends HttpServlet {
private static final long serialVersionUID = 1L;
public updateProcessUserHistory() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
String driverName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/gamingsite";
String user = "root";
String psw = "";
String name = request.getParameter("name");
String username=request.getParameter("username");
String mobile=request.getParameter("mobile");
String email=request.getParameter("email");
String country=request.getParameter("country");
PrintWriter out = response.getWriter();
if(username != null)
{
Connection con = null;
PreparedStatement ps = null;
int personID = Integer.parseInt(username);
try
{
Class.forName(driverName);
con = DriverManager.getConnection(url,user,psw);
String sql="Update users set name=?,username=?,mobile=?,email=?,country=? where username="+personID;
ps = con.prepareStatement(sql);
ps.setString(1,name);
ps.setString(2, username);
ps.setString(3, mobile);
ps.setString(4, email);
ps.setString(5, country);
int i = ps.executeUpdate();
if(i > 0)
{
out.print("Record Updated Successfully");
response.sendRedirect("displayUserHistory.jsp") ;
}
else
{
out.print("There is a problem in updating Record.");
}
}
catch(SQLException | ClassNotFoundException sql)
{
request.setAttribute("error", sql);
out.println(sql);
}
}
}
}