Java OOP association SQL equivalent

1 week ago 8
ARTICLE AD BOX

I have two classes: Student and Group.

Student attributes:

private String registrationNumber; private String firstName; private String lastName; private Date dateOfBirth; private String password; private Groupe groupe; private List<Grades> studentGrades;

Student Constructor:

public Student(String registrationNumber, String firstName, String lastName, Date dateOfBirth, Groupe groupe,String password) { super(); this.registrationNumber = registrationNumber; this.firstName = firstName; this.lastName = lastName; this.dateOfBirth = dateOfBirth; this.groupe = groupe; this.password=password; }

Group attributes:

private int idGroup; private String nameGroup; private List<Student> students; private List<Subject> subjects;

Its constructor takes only idGroup and nameGroup.

When registering, a student will select a group from a drop down menu (Swing interface) which will then call the addStudent function (controller to DAO).

public boolean addStudent( Student s) throws SQLException { myStatement=myConnection.getMyConnection().createStatement(); String request="insert into student values('"+s.getRegistrationNumber()+"','"+s.getFirstName()+"','"+s.getLastName()+"','"+s.getDateOfBirth()+"','"+s.getPassword()+"')"; return myStatement.executeUpdate(request)>0; }

How should I translate the group attribute (and by extension all other associations) from OOP to a relational format?

Should I drop these association from student and use an int attribute that represents a foreign key which refrences the Group table's primary key and rely on joins for the List (1..n associations)?

Read Entire Article