Package edu.pdx.cs.joy.jdbc
Class CourseDAOImpl
java.lang.Object
edu.pdx.cs.joy.jdbc.CourseDAOImpl
- All Implemented Interfaces:
CourseDAO
Data Access Object implementation for managing Course entities in the database.
Demonstrates basic JDBC operations: CREATE, READ, UPDATE.
-
Constructor Summary
ConstructorsConstructorDescriptionCourseDAOImpl(Connection connection) Creates a new CourseDAOImpl with the specified database connection. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateTable(Connection connection) Creates the courses table in the database.static voiddropTable(Connection connection) Drops the courses table from the database if it exists.findByDepartmentId(int departmentId) Finds all courses associated with a specific department.findByTitle(String title) Finds a course by its title.voidSaves a course to the database.voidUpdates an existing course in the database.
-
Constructor Details
-
CourseDAOImpl
Creates a new CourseDAOImpl with the specified database connection.- Parameters:
connection- the database connection to use
-
-
Method Details
-
dropTable
Drops the courses table from the database if it exists.- Parameters:
connection- the database connection to use- Throws:
SQLException- if a database error occurs
-
createTable
Creates the courses table in the database.- Parameters:
connection- the database connection to use- Throws:
SQLException- if a database error occurs
-
save
Saves a course to the database. The course's ID will be automatically generated by the database and set on the object.- Specified by:
savein interfaceCourseDAO- Parameters:
course- the course to save- Throws:
SQLException- if a database error occurs
-
findByTitle
Finds a course by its title.- Specified by:
findByTitlein interfaceCourseDAO- Parameters:
title- the title to search for- Returns:
- the course with the given title, or null if not found
- Throws:
SQLException- if a database error occurs
-
findByDepartmentId
Finds all courses associated with a specific department.- Specified by:
findByDepartmentIdin interfaceCourseDAO- Parameters:
departmentId- the department ID to search for- Returns:
- a list of courses in the department
- Throws:
SQLException- if a database error occurs
-
update
Updates an existing course in the database. Uses the course's ID to identify which record to update.- Specified by:
updatein interfaceCourseDAO- Parameters:
course- the course to update- Throws:
SQLException- if a database error occurs
-