-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppointmentDao.java
More file actions
26 lines (21 loc) · 995 Bytes
/
Copy pathAppointmentDao.java
File metadata and controls
26 lines (21 loc) · 995 Bytes
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
package com.dao;
import com.db.DbConnect;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class AppointmentDao {
private static final String INSERT_APPOINTMENT_SQL = "INSERT INTO appointments (patient_id, doctor_name, appointment_date_time) VALUES (?, ?, ?)";
public static boolean bookAppointment(String patientId, String doctorName, String dateTime) {
try (Connection connection = DbConnect.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(INSERT_APPOINTMENT_SQL)) {
preparedStatement.setString(1, patientId);
preparedStatement.setString(2, doctorName);
preparedStatement.setString(3, dateTime);
int rowsAffected = preparedStatement.executeUpdate();
return rowsAffected > 0;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
}