Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. public long getEmployeeTypeByUsernameAndPassword(String username, String password) {
  2.         Connection conn = DBConnection.openConnection();
  3.         Statement stmt = null;
  4.         long result = 0l;
  5.         String employeeType ="";
  6.  
  7.         try {
  8.             System.out.println("Creating statement...");
  9.             stmt = conn.createStatement();
  10.             String sql = "SELECT e.EMPLOYEE_ID, e.USERNAME, e.PASSWORD, ut.USER_TYPE " +
  11.                     "FROM EMPLOYEE_TABLE e, USER_TYPE_TABLE ut " +
  12.                     "WHERE e.EMPLOYEE_ID= ut.EMPLOYEE_ID AND e.USERNAME='" +username +"'AND e.PASSWORD='" + password + "'";
  13.             ResultSet resultSet = stmt.executeQuery(sql);
  14.             while (resultSet.next()) {
  15.                 Long id = resultSet.getLong("EMPLOYEE_ID");
  16.                 String uname = resultSet.getString("USERNAME");
  17.                 String pass = resultSet.getString("PASSWORD");
  18.                 employeeType = resultSet.getString("USER_TYPE");
  19.  
  20.                 String output = "Employee:\t # EmployeeID:%d - Username:%s - Password:%s - UserType:%s";
  21.                 System.out.println(String.format(output, id, uname, pass, employeeType));
  22.             }
  23.             if (employeeType.equals(""))
  24.             {
  25.                 //nothing to do
  26.             }
  27.             else
  28.             if (employeeType.equals("Admin") || employeeType.equals("admin")) {
  29.                 result = 1;
  30.             }
  31.             else if (employeeType.equals("Angajat")|| employeeType.equals("angajat"))
  32.                 result = 2;
  33.             return result;
  34.  
  35.         } catch (SQLException e) {
  36.             e.printStackTrace();
  37.         }
  38.         DBConnection.closeConnection(conn, stmt);
  39.         return 0;
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement