Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public long getEmployeeTypeByUsernameAndPassword(String username, String password) {
- Connection conn = DBConnection.openConnection();
- Statement stmt = null;
- long result = 0l;
- String employeeType ="";
- try {
- System.out.println("Creating statement...");
- stmt = conn.createStatement();
- String sql = "SELECT e.EMPLOYEE_ID, e.USERNAME, e.PASSWORD, ut.USER_TYPE " +
- "FROM EMPLOYEE_TABLE e, USER_TYPE_TABLE ut " +
- "WHERE e.EMPLOYEE_ID= ut.EMPLOYEE_ID AND e.USERNAME='" +username +"'AND e.PASSWORD='" + password + "'";
- ResultSet resultSet = stmt.executeQuery(sql);
- while (resultSet.next()) {
- Long id = resultSet.getLong("EMPLOYEE_ID");
- String uname = resultSet.getString("USERNAME");
- String pass = resultSet.getString("PASSWORD");
- employeeType = resultSet.getString("USER_TYPE");
- String output = "Employee:\t # EmployeeID:%d - Username:%s - Password:%s - UserType:%s";
- System.out.println(String.format(output, id, uname, pass, employeeType));
- }
- if (employeeType.equals(""))
- {
- //nothing to do
- }
- else
- if (employeeType.equals("Admin") || employeeType.equals("admin")) {
- result = 1;
- }
- else if (employeeType.equals("Angajat")|| employeeType.equals("angajat"))
- result = 2;
- return result;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- DBConnection.closeConnection(conn, stmt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment