-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatabaseStorer.java
65 lines (52 loc) · 1.99 KB
/
DatabaseStorer.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
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
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("/DatabaseStorer")
public class DatabaseStorer extends HttpServlet {
private static final long serialVersionUID = 1L;
public DatabaseStorer() {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out=response.getWriter();
String userNumber=request.getParameter("userNumber");
String followNumber=request.getParameter("followNumber");
String dbName="farmerzone";
String followTableName = "follow";
try {
int what=Integer.valueOf(request.getParameter("what"));
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + dbName, "Bootathon", "6383411123");
Statement statement = connection.createStatement();
if(userNumber!=null) {
if(followNumber!=null||!followNumber.isEmpty()) {
if(what==1) {
statement.executeUpdate("delete from "+followTableName+" where (follower='"+userNumber+"' and following='"+followNumber+"')");//0 following 1
out.println("Follow");
}
else {
statement.executeUpdate("insert into "+followTableName+" values('"+userNumber+"','"+followNumber+"')");//0 following 1
out.println("Following");
}
}
else {
out.println("Follow fnum=null");
}
}
else {
out.println("Follow unum=null");
}
}catch (Exception e) {
out.println(e);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}