Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

JAVA Developer Training

23. EnrollCourseDB 본문

트레이닝

23. EnrollCourseDB

Romenest 2021. 9. 2. 16:44
public class App {
    public static void main(String[] args) throws Exception {

        //수강 등록 , 등록을 위해선 학생과, 과목의 정보가 필요해서 호출했다. 기능을 따로추가함
        Student student = StudentDB.getInstance().selectStudentOne(39);
        Course course = CourseDB.getInstance().selectCourseOne(5);

        Enrollcourse enrollcourse = new Enrollcourse();

        enrollcourse.setEncno(null);
        enrollcourse.setClassroom("방4");
        enrollcourse.setEncdata(new Date());
        enrollcourse.setStudent(student);
        enrollcourse.setCourse(course);

        boolean ret = EnrollCourseDB.getInstance().insertEnroll(enrollcourse);

        System.out.println(ret);
    }
}

추가한 자료

//학생 지정조회
    public Student selectStudentOne(long no) {
        Bson filter = Filters.eq("_id", no);
        MongoCursor<Document> cursor = studentCollection.find(filter).cursor();

        if (cursor.hasNext()) {
            Document doc = cursor.next();

            Student student = new Student();

            student.setStdid(doc.getLong("_id"));
            student.setStdname(doc.getString("name"));
            student.setStdmajor(doc.getString("major"));
            student.setStddate(doc.getDate("stddate"));

            return student;

        }
        return null;
    }
    
    
    
    // 과목 번호 지정 조회
    public Course selectCourseOne(long no) {
        Bson filter = Filters.eq("_id", no);
        MongoCursor<Document> cursor = courseCollection.find(filter).cursor();

        if (cursor.hasNext()) {
            Document doc = cursor.next();

            Course course = new Course();

            course.setCorcode(doc.getLong("_id"));
            course.setCorname(doc.getString("name"));
            course.setCorpoint(doc.getInteger("point"));
            course.setCordate(doc.getDate("cordate"));

            return course;

        }
        return null;
    }

'트레이닝' 카테고리의 다른 글

25. JAVA spring 이용  (0) 2021.09.06
24. EnrollCourseDB 교수정보 받기  (0) 2021.09.02
22. CourseDB  (0) 2021.09.02
21. ProfessorDB  (0) 2021.09.02
20. Student DB ( 학생 페이지별 조회, 원하는 형태로 데이터 넣기 )  (0) 2021.09.02