Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. public void getSubjets(Student student) throws SQLServerException, SQLException {
  2. List<Subject> subjects = new ArrayList();
  3. try (Connection con = dbConnector.getConnection()) {
  4.  
  5. String sql = "SELECT su.name, ab.isAbsent FROM clazz cl "
  6. + "JOIN Subjectz su ON su.classId = cl.id "
  7. + "JOIN Modulez mo ON mo.subjectId = su.id "
  8. + "JOIN Absence ab ON ab.moduleId = mo.id "
  9. + "JOIN Uzer uz ON uz.id = ab.userId "
  10. + "WHERE uz.id = ?";
  11.  
  12. PreparedStatement statement = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
  13.  
  14. statement.setInt(1, student.getId());
  15.  
  16. ResultSet rs = statement.executeQuery();
  17.  
  18. while (rs.next()) {
  19. Subject sub;
  20. String subName = rs.getString("name");
  21. int subIndex = subjects.indexOf(subName);
  22. if (subIndex == -1) {
  23. sub = new Subject(subName, 0, 0);
  24. subjects.add(sub);
  25. if (rs.getBoolean("isAbsent")) {
  26. subjects.get(subIndex).opAbsence();
  27. }
  28. } else {
  29. subjects.get(subIndex).opTotal();
  30. if (rs.getBoolean("isAbsent")) {
  31. subjects.get(subIndex).opAbsence();
  32. }
  33. }
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement