source: src/main/java/service/impl/StudentServiceImpl.java@ 1eb7a55

Last change on this file since 1eb7a55 was 1eb7a55, checked in by Elena Markovska <elena.elenamarkovska@…>, 11 days ago

Initial commit - Scholaris project code

  • Property mode set to 100644
File size: 1.7 KB
Line 
1package service.impl;
2
3import DAO.impl.StudentDAOImpl;
4import model.Student;
5import service.StudentService;
6
7import java.sql.SQLException;
8import java.util.List;
9
10public class StudentServiceImpl implements StudentService {
11
12 StudentDAOImpl studentDAO = new StudentDAOImpl();
13
14 @Override
15 public List<Student> getAllStudent() throws SQLException {
16 List<Student> student = studentDAO.getAll();
17 return student;
18 }
19
20 @Override
21 public Student getById(Long id) throws SQLException {
22 try{
23 return studentDAO.getByID(id);
24 } catch (SQLException e) {
25 System.out.println("Error fetching student with ID " + id + ": " + e.getMessage());
26 throw e;
27 }
28 }
29
30 @Override
31 public void update(Student student) {
32 try {
33 studentDAO.update(student);
34 System.out.println("Successfully updated student: " + student);
35 } catch (SQLException e) {
36 System.out.println("Error updating student: " + student + ". " + e.getMessage());
37 throw new RuntimeException("Failed to update student", e);
38 }
39 }
40
41 @Override
42 public void delete(Long id) throws SQLException {
43 studentDAO.delete(id);
44 System.out.println("Successfully deleted student with ID: " + id);
45 }
46
47 @Override
48 public void save(Student student) {
49 try {
50 studentDAO.save(student);
51 System.out.println("Successfully saved student: " + student);
52 } catch (SQLException e) {
53 System.out.println("Error saving student: " + student + ". " + e.getMessage());
54 throw new RuntimeException("Failed to save student", e);
55 }
56 }
57}
Note: See TracBrowser for help on using the repository browser.