Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ArrayList<Employee> getAllEmployes() {
- ArrayList<Employee> list = new ArrayList<Employee>();
- Statement stmt = null;
- try {
- if (conn != null) {
- stmt = (Statement) conn.createStatement();
- stmt.executeQuery("SELECT e.*, l.Name, max(a.TimeS), p.photo"
- + "from employes e , photos p, locals l, accesses a \r\n"
- + "where e.SerialNumber = p.IdEmployee and e.Causal IS NULL and a.IdEmployee=e.SerialNumber and l.Id=a.IdLocal\r\n"
- + "GROUP BY e.SerialNumber");
- ResultSet rs = stmt.getResultSet();
- while (rs.next()) {
- String serial = rs.getString("SerialNumber");
- String name = rs.getString("Name");
- String surname = rs.getString("Surname");
- String auth = rs.getString("AuthGrade");
- String position = rs.getString("l.Name");
- String photo = rs.getString("p.photo");
- Employee temp = new Employee(serial, name, surname, auth, position);
- temp.setPhoto(photo);
- list.add(temp);
- }
- stmt.executeQuery("SELECT e.*, p.photo from employes, photo p e\r\n"
- + "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"
- + " where a.IdEmployee=e.SerialNumber and l.Id=a.IdLocal GROUP BY e.SerialNumber)\r\n"
- + "");
- rs = stmt.getResultSet();
- while (rs.next()) {
- String serial = rs.getString("SerialNumber");
- String name = rs.getString("Name");
- String surname = rs.getString("Surname");
- String auth = rs.getString("AuthGrade");
- String position = "No position found";
- String photo = rs.getString("p.photo");
- Employee temp = new Employee(serial, name, surname, auth, position);
- temp.setPhoto(photo);
- list.add(temp);
- }
- return list;
- }
- } catch (SQLException ex) {
- System.out.println("Error: access problem while loading!");
- } finally {
- try {
- if (conn != null)
- conn.close();
- if (stmt != null)
- stmt.close();
- } catch (SQLException e) {
- System.out.println("Error closing " + e.getMessage());
- }
- }
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement