-
Notifications
You must be signed in to change notification settings - Fork 0
/
Customer_Payment.java
57 lines (50 loc) · 2.31 KB
/
Customer_Payment.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
package cus_pay;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cus_reg.DBUtil;
@WebServlet("/Customer_Payment")
@MultipartConfig
public class Customer_Payment extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String holderName = request.getParameter("cardHolder");
String paymentMethod = request.getParameter("payment_method");
String cardNumber = request.getParameter("cardNumber");
String payDate = request.getParameter("payDate");
String amount = request.getParameter("amount");
Connection connection = null;
try {
connection = DBUtil.getConnection();
PreparedStatement stmt;
String query = "INSERT INTO payment (holderName, paymentMethod, cardNumber, payDate, amount) VALUES (?, ?, ?, ?, ?)";
stmt = connection.prepareStatement(query);
stmt.setString(1, holderName);
stmt.setString(2, paymentMethod);
stmt.setString(3, cardNumber);
stmt.setString(4, payDate);
stmt.setString(5, amount);
int row = stmt.executeUpdate();
if (row > 0) {
System.out.println("Payment details added into database successfully...");
response.sendRedirect("payment_details.jsp?cardHolder=" + holderName +
"&payment_method=" + paymentMethod +
"&cardNumber=" + cardNumber +
"&payDate=" + payDate +
"&amount=" + amount);
} else {
System.out.println("Failed to add payment details into Database...");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeConnection(connection);
}
}
}