-
Notifications
You must be signed in to change notification settings - Fork 0
/
Payconfirm.java
79 lines (71 loc) · 2.7 KB
/
Payconfirm.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
71
72
73
74
75
76
77
78
79
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class Payconfirm
*/
@WebServlet("/Payconfirm")
public class Payconfirm extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
HttpSession ses=request.getSession();
String number=String.valueOf(ses.getAttribute("pno"));
String productName = request.getParameter("prod");
String quantity = request.getParameter("quan");
String desc = request.getParameter("desc");
String price = request.getParameter("price");
String phoneNumber = request.getParameter("farmer");
String farmloc= request.getParameter("farmerloc");
HttpSession s=request.getSession();
String conloc=String.valueOf(s.getAttribute("consloc"));
LocalDateTime dTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd");
String date=dTime.format(formatter);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/farmerzone", "Bootathon","6383411123");
PreparedStatement st=con.prepareStatement("Insert into payment values(?,?,?,?,?,?,?,?,?,?)");
st.setString(1,productName);
st.setString(2,quantity);
st.setString(3, desc);
st.setString(4, price);
st.setString(5, phoneNumber);
st.setString(6,farmloc);
st.setString(7, conloc);
st.setString(8, number);
st.setString(9, "waiting");
st.setString(10, date);
int r1=st.executeUpdate();
if(r1>0) {
// pw.println("<script>alert('Phone number already registered')</script>");
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Consumation.jsp");
dispatcher.forward(request, response);
}
else
{
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Payment.jsp");
dispatcher.forward(request, response);
}
con.close();
}
catch(Exception ec)
{
System.out.print(ec);
}
}
}