Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. public static ArrayList<Employee> getAllEmployes() {
  2. ArrayList<Employee> list = new ArrayList<Employee>();
  3. Statement stmt = null;
  4. try {
  5. if (conn != null) {
  6. stmt = (Statement) conn.createStatement();
  7. stmt.executeQuery("SELECT e.*, l.Name, max(a.TimeS), p.photo"
  8. + "from employes e , photos p, locals l, accesses a \r\n"
  9. + "where e.SerialNumber = p.IdEmployee and e.Causal IS NULL and a.IdEmployee=e.SerialNumber and l.Id=a.IdLocal\r\n"
  10. + "GROUP BY e.SerialNumber");
  11. ResultSet rs = stmt.getResultSet();
  12. while (rs.next()) {
  13. String serial = rs.getString("SerialNumber");
  14. String name = rs.getString("Name");
  15. String surname = rs.getString("Surname");
  16. String auth = rs.getString("AuthGrade");
  17. String position = rs.getString("l.Name");
  18. String photo = rs.getString("p.photo");
  19.  
  20. Employee temp = new Employee(serial, name, surname, auth, position);
  21. temp.setPhoto(photo);
  22. list.add(temp);
  23. }
  24. stmt.executeQuery("SELECT e.*, p.photo from employes, photo p e\r\n"
  25. + "where e.SerialNumber = p.IdEmployee and e.Causal IS NULL and e.SerialNumber not in(SELECT e.SerialNumber from employes e , locals l, accesses a \r\n"
  26. + " where a.IdEmployee=e.SerialNumber and l.Id=a.IdLocal GROUP BY e.SerialNumber)\r\n"
  27. + "");
  28. rs = stmt.getResultSet();
  29. while (rs.next()) {
  30. String serial = rs.getString("SerialNumber");
  31. String name = rs.getString("Name");
  32. String surname = rs.getString("Surname");
  33. String auth = rs.getString("AuthGrade");
  34. String position = "No position found";
  35. String photo = rs.getString("p.photo");
  36.  
  37. Employee temp = new Employee(serial, name, surname, auth, position);
  38. temp.setPhoto(photo);
  39. list.add(temp);
  40.  
  41. }
  42. return list;
  43. }
  44. } catch (SQLException ex) {
  45. System.out.println("Error: access problem while loading!");
  46.  
  47. } finally {
  48. try {
  49. if (conn != null)
  50. conn.close();
  51. if (stmt != null)
  52. stmt.close();
  53. } catch (SQLException e) {
  54. System.out.println("Error closing " + e.getMessage());
  55. }
  56. }
  57. return list;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement