Search in sources :

Example 1 with CompanyBean

use of models.CompanyBean in project bil372-proje by mertserezli.

the class SearchServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    String searchType = request.getParameter("searchType");
    String toSearch = request.getParameter("searchBar");
    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    if (searchType.equals("users")) {
        List<UserBean> users = null;
        String category = request.getParameter("userCategory");
        if (category.equals("username")) {
            try {
                users = SearchDAO.searchForUser(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting users from DB", e);
            }
        } else if (category.equals("jobtitle")) {
            try {
                users = SearchDAO.searchForUserJobTitle(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting users from DB", e);
            }
        } else if (category.equals("qualifications")) {
            try {
                users = SearchDAO.searchForUserWithQualifications(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting users from DB", e);
            }
        }
        for (UserBean u : users) {
            pw.println("<a href=\"profile.jsp?username=" + u.getUsername() + "\"style=\"display:block\">" + u.getUsername() + "</a>");
        }
    } else if (searchType.equals("projects")) {
        List<ProjectBean> projects = null;
        String category = request.getParameter("projectCategory");
        if (category.equals("title")) {
            try {
                projects = SearchDAO.searchForProject(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting projects from DB", e);
            }
        } else if (category.equals("description")) {
            try {
                projects = SearchDAO.searchForProjectDescription(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting projects from DB", e);
            }
        } else if (category.equals("tags")) {
            try {
                projects = SearchDAO.searchForProjectWithTags(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting projects from DB", e);
            }
        }
        for (ProjectBean p : projects) {
            pw.println("<a href=\"project.jsp?pid=" + p.getPid() + "\"style=\"display:block\">" + p.getTitle() + "</a>");
        }
    } else if (searchType.equals("companies")) {
        List<CompanyBean> companies = null;
        String category = request.getParameter("companyCategory");
        if (category.equals("name")) {
            try {
                companies = SearchDAO.searchForCompany(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting  companies from DB", e);
            }
        } else if (category.equals("description")) {
            try {
                companies = SearchDAO.searchForCompanyDescription(toSearch);
            } catch (SQLException e) {
                throw new ServletException("Error when getting  companies from DB", e);
            }
        }
        for (CompanyBean c : companies) {
            pw.println("<a href=\"company.jsp?name=" + c.getName() + "\"style=\"display:block\">" + c.getName() + "</a>");
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) UserBean(models.UserBean) SQLException(java.sql.SQLException) ProjectBean(models.ProjectBean) List(java.util.List) CompanyBean(models.CompanyBean) PrintWriter(java.io.PrintWriter)

Example 2 with CompanyBean

use of models.CompanyBean in project bil372-proje by mertserezli.

the class SearchDAO method searchForCompanyDescription.

public static List<CompanyBean> searchForCompanyDescription(String descriptionRequest) throws SQLException {
    List<CompanyBean> result = new ArrayList<CompanyBean>();
    PreparedStatement ps = null;
    String searchQuery = "Select DISTINCT * From COMPANY Where UPPER(Description) LIKE UPPER('%" + descriptionRequest + "%')";
    try {
        ConnectionManager connect = new ConnectionManager();
        currentConnection = connect.getConnection();
        ps = currentConnection.prepareStatement(searchQuery);
        rs = ps.executeQuery();
        while (rs.next()) {
            CompanyBean company = new CompanyBean();
            company.setCompID(rs.getString("CompId"));
            company.setName(rs.getString("Name"));
            company.setDescription(rs.getString("Description"));
            result.add(company);
        }
    } finally {
        finalizeConnection(currentConnection, ps, rs);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) CompanyBean(models.CompanyBean)

Example 3 with CompanyBean

use of models.CompanyBean in project bil372-proje by mertserezli.

the class SearchDAO method searchForCompany.

public static List<CompanyBean> searchForCompany(String companyRequest) throws SQLException {
    List<CompanyBean> result = new ArrayList<CompanyBean>();
    PreparedStatement ps = null;
    String searchQuery = "Select DISTINCT * From COMPANY Where UPPER(name) LIKE UPPER('%" + companyRequest + "%')";
    try {
        ConnectionManager connect = new ConnectionManager();
        currentConnection = connect.getConnection();
        ps = currentConnection.prepareStatement(searchQuery);
        rs = ps.executeQuery();
        while (rs.next()) {
            CompanyBean company = new CompanyBean();
            company.setCompID(rs.getString("CompId"));
            company.setName(rs.getString("Name"));
            company.setDescription(rs.getString("Description"));
            result.add(company);
        }
    } finally {
        finalizeConnection(currentConnection, ps, rs);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) CompanyBean(models.CompanyBean)

Aggregations

CompanyBean (models.CompanyBean)3 PreparedStatement (java.sql.PreparedStatement)2 ArrayList (java.util.ArrayList)2 PrintWriter (java.io.PrintWriter)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 ProjectBean (models.ProjectBean)1 UserBean (models.UserBean)1