| 4 | |
| 5 | public class PatientDAO { |
| 6 | public void addPatient(Patient patient) throws SQLException { |
| 7 | Connection conn = DatabaseConnection.getConnection(); |
| 8 | String query = "INSERT INTO patients (id, name, age, gender) VALUES (?, ?, ?, ?)"; |
| 9 | PreparedStatement stmt = conn.prepareStatement(query); |
| 10 | stmt.setInt(1, patient.getId()); |
| 11 | stmt.setString(2, patient.getName()); |
| 12 | stmt.setInt(3, patient.getAge()); |
| 13 | stmt.setString(4, patient.getGender()); |
| 14 | stmt.executeUpdate(); |
| 15 | stmt.close(); |
| 16 | conn.close(); |
| 17 | } |
| 18 | } |