This is the solution I have come up with after implementing everyone's input in case someone else runs into a similar problem.
Starting with the student table:
| registration Number | firstName | lastName | dateofBirth | password | idGroup |
|---|
The updated addStudent function with SQL injection safety (Thanks for the clarification Tim Moore) :
public boolean addStudent( Student s) throws SQLException {
String request="INSERT INTO student values (?,?,?,?,?,?);";
PreparedStatement pst=myConnection.getMyConnection().prepareStatement(request);
pst.setString(1, s.getRegistrationNumber());
pst.setString(2, s.getFirstName());
pst.setString(3, s.getLastName());
pst.setDate(4, s.getDateOfBirth());
pst.setString(5, s.getPassword());
pst.setInt(6, s.getGroup().getIdGroup());
return pst.executeUpdate()>0;
}
s.getGroup().getIdGroup() saves the student's group to the foreign key idGroup.