Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void getSubjets(Student student) throws SQLServerException, SQLException {
- List<Subject> subjects = new ArrayList();
- try (Connection con = dbConnector.getConnection()) {
- String sql = "SELECT su.name, ab.isAbsent FROM clazz cl "
- + "JOIN Subjectz su ON su.classId = cl.id "
- + "JOIN Modulez mo ON mo.subjectId = su.id "
- + "JOIN Absence ab ON ab.moduleId = mo.id "
- + "JOIN Uzer uz ON uz.id = ab.userId "
- + "WHERE uz.id = ?";
- PreparedStatement statement = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
- statement.setInt(1, student.getId());
- ResultSet rs = statement.executeQuery();
- while (rs.next()) {
- Subject sub;
- String subName = rs.getString("name");
- int subIndex = subjects.indexOf(subName);
- if (subIndex == -1) {
- sub = new Subject(subName, 0, 0);
- subjects.add(sub);
- if (rs.getBoolean("isAbsent")) {
- subjects.get(subIndex).opAbsence();
- }
- } else {
- subjects.get(subIndex).opTotal();
- if (rs.getBoolean("isAbsent")) {
- subjects.get(subIndex).opAbsence();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement