We still haven't completed the functionality for adding a new course; we need to provide an option to assign a teacher to a course when adding a new course. Assuming that you have implemented TeacherDAO and created addTeacher and getTeachers methods in the Teacher bean, we can now complete the add course functionality.
First, modify addCourse in CourseADO to save the teacher ID for each course, if it is not zero. The SQL statement to insert course changes is as follows:
String sql = "insert into Course (name, credits, Teacher_id) values (?,?,?)";
We have added the Teacher_id column and the corresponding parameter holder ?. We will set Teacher_id to null if it is zero; or else the actual value:
if (course.getTeacherId() ...