Package edu.pdx.cs.joy.jdbc
Class DepartmentDAOImpl
java.lang.Object
edu.pdx.cs.joy.jdbc.DepartmentDAOImpl
- All Implemented Interfaces:
DepartmentDAO
Data Access Object implementation for managing Department entities in the database.
Demonstrates JDBC operations with auto-generated keys: CREATE, READ, UPDATE, DELETE.
-
Constructor Summary
ConstructorsConstructorDescriptionDepartmentDAOImpl(Connection connection) Creates a new DepartmentDAOImpl with the specified database connection. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateTable(Connection connection) Creates the departments table in the database if it does not already exist.voiddelete(int id) Deletes a department from the database by ID.static voiddropTable(Connection connection) Drops the departments table from the database if it exists.findAll()Finds all departments in the database.findById(int id) Finds a department by its ID.findByName(String name) Finds a department by its name.voidsave(Department department) Saves a department to the database.voidupdate(Department department) Updates an existing department in the database.
-
Constructor Details
-
DepartmentDAOImpl
Creates a new DepartmentDAOImpl with the specified database connection.- Parameters:
connection- the database connection to use
-
-
Method Details
-
dropTable
Drops the departments table from the database if it exists.- Parameters:
connection- the database connection to use- Throws:
SQLException- if a database error occurs
-
createTable
Creates the departments table in the database if it does not already exist.- Parameters:
connection- the database connection to use- Throws:
SQLException- if a database error occurs
-
save
Saves a department to the database. The department's ID will be automatically generated by the database.- Specified by:
savein interfaceDepartmentDAO- Parameters:
department- the department to save- Throws:
SQLException- if a database error occurs
-
findById
Finds a department by its ID.- Specified by:
findByIdin interfaceDepartmentDAO- Parameters:
id- the ID to search for- Returns:
- the department with the given ID, or null if not found
- Throws:
SQLException- if a database error occurs
-
findByName
Finds a department by its name.- Specified by:
findByNamein interfaceDepartmentDAO- Parameters:
name- the name to search for- Returns:
- the department with the given name, or null if not found
- Throws:
SQLException- if a database error occurs
-
findAll
Finds all departments in the database.- Specified by:
findAllin interfaceDepartmentDAO- Returns:
- a list of all departments
- Throws:
SQLException- if a database error occurs
-
update
Updates an existing department in the database.- Specified by:
updatein interfaceDepartmentDAO- Parameters:
department- the department to update- Throws:
SQLException- if a database error occurs
-
delete
Deletes a department from the database by ID.- Specified by:
deletein interfaceDepartmentDAO- Parameters:
id- the ID of the department to delete- Throws:
SQLException- if a database error occurs
-