-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookAppointmentServlet.java
More file actions
56 lines (47 loc) · 1.98 KB
/
Copy pathBookAppointmentServlet.java
File metadata and controls
56 lines (47 loc) · 1.98 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
package com.servlet;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import com.db.DbConnect;
@WebServlet("/BookAppointmentServlet")
public class BookAppointmentServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String doctorName = request.getParameter("doctorName");
String dateTime = request.getParameter("dateTime");
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = DbConnect.getConnection();
String sql = "INSERT INTO appointments (patient_name, doctor_name, appointment_time) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(sql);
stmt.setString(1, username);
stmt.setString(2, doctorName);
stmt.setString(3, dateTime);
stmt.executeUpdate();
response.sendRedirect("patient_module.jsp");
} catch (SQLException e) {
e.printStackTrace();
response.getWriter().println("An error occurred while booking the appointment.");
} catch (Exception e) {
e.printStackTrace();
response.getWriter().println("An unexpected error occurred.");
} finally {
ResultSet rs = null;
DbConnect.close(conn, stmt, null);
try {
if (stmt != null) stmt.close();
} catch (SQLException se2) {
se2.printStackTrace();
}
}
}
}