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>");
}
}
}
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;
}
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;
}
Aggregations