Class CourseDAOImpl

java.lang.Object
edu.pdx.cs.joy.jdbc.CourseDAOImpl
All Implemented Interfaces:
CourseDAO

public class CourseDAOImpl extends Object implements CourseDAO
Data Access Object implementation for managing Course entities in the database. Demonstrates basic JDBC operations: CREATE, READ, UPDATE.
  • Constructor Details

    • CourseDAOImpl

      public CourseDAOImpl(Connection connection)
      Creates a new CourseDAOImpl with the specified database connection.
      Parameters:
      connection - the database connection to use
  • Method Details

    • dropTable

      public static void dropTable(Connection connection) throws SQLException
      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

      public static void createTable(Connection connection) throws SQLException
      Creates the courses table in the database.
      Parameters:
      connection - the database connection to use
      Throws:
      SQLException - if a database error occurs
    • save

      public void save(Course course) throws SQLException
      Saves a course to the database. The course's ID will be automatically generated by the database and set on the object.
      Specified by:
      save in interface CourseDAO
      Parameters:
      course - the course to save
      Throws:
      SQLException - if a database error occurs
    • findByTitle

      public Course findByTitle(String title) throws SQLException
      Finds a course by its title.
      Specified by:
      findByTitle in interface CourseDAO
      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

      public List<Course> findByDepartmentId(int departmentId) throws SQLException
      Finds all courses associated with a specific department.
      Specified by:
      findByDepartmentId in interface CourseDAO
      Parameters:
      departmentId - the department ID to search for
      Returns:
      a list of courses in the department
      Throws:
      SQLException - if a database error occurs
    • update

      public void update(Course course) throws SQLException
      Updates an existing course in the database. Uses the course's ID to identify which record to update.
      Specified by:
      update in interface CourseDAO
      Parameters:
      course - the course to update
      Throws:
      SQLException - if a database error occurs