public class Data extends HttpServlet { // Это наша JSP страница String page = "DataPage.jsp"; String password = "root"; String login = "root"; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); // Устанавливаем соединение с БД String url = "jdbc:postgresql://localhost:5432/root"; Connection connection = null; ResultSet rs; response.setContentType("text/html"); List dataList = new ArrayList(); try { Class.forName("org.postgresql.Driver"); connection = DriverManager.getConnection(url, login, password); String sql = "select * fiz_phone"; Statement s = connection.createStatement(); s.executeQuery(sql); rs = s.getResultSet(); ArrayList rows = new ArrayList(); while (rs.next()) { DBRow row = new DBRow(); row.setId(rs.getInt("id")); row.setName(rs.getString("name")); row.setAdress(rs.getString("adress")); row.setPhone(rs.getString("phone")); row.setPhone_adress(rs.getString("phone_adress")); row.setCost(rs.getInt("cost")); row.setExempt_type(rs.getString("exempt_type")); row.setExempt(rs.getInt("exempt")); row.setDate_claim(rs.getString("date_claim")); row.setNumber_claim(rs.getInt("number_claim")); row.setInspektor(rs.getString("inspektor")); row.setDate_repair(rs.getString("date_repair")); row.setPhone_cost(rs.getInt("phone_cost")); row.setCall(rs.getString("call")); rows.add(row) } rs.close(); s.close(); } catch (Exception e) { System.out.println("Exception is ;" + e); } request.setAttribute("data", rows); // Переходим на JSP страницу RequestDispatcher dispatcher = request.getRequestDispatcher(page); if (dispatcher != null) { dispatcher.forward(request, response); } } } public class DBRow{ private int id; private String name; private String adress; private String phone; private String phone_adress; private int cost; private String exempt_type; private int exempt; private String date_claim; private int number_claim; private String inspektor; private String date_repair; private int phone_cost; private String call; public void setId(int id) { this.id = id; } public void setName(String name) { this.name = name; } public void setAdress(String adress) { this.adress = adress; } public void setPhone(String phone) { this.phone = phone; } public void setPhone_adress(String phone_adress) { this.phone_adress = phone_adress; } public void setCost(int cost) { this.cost = cost; } public void setExempt_type(String exempt_type) { this.exempt_type = exempt_type; } public void setExempt(int exempt) { this.exempt = exempt; } public void setDate_claim(String date_claim) { this.date_claim = date_claim; } public void setNumber_claim(int number_claim) { this.number_claim = number_claim; } public void setInspektor(String inspektor) { this.inspektor = inspektor; } public void setDate_repair(String date_repair) { this.date_repair = date_repair; } public void setPhone_cost(int phone_cost) { this.phone_cost = phone_cost; } public void setCall(String call) { this.call = call; } public String getName() { return name; } public String getAdress() { return adress; } public String getPhone() { return phone; } public String getPhone_adress() { return phone_adress; } public int getCost() { return cost; } public String getExempt_type() { return exempt_type; } public String getDate_claim() { return date_claim; } public int getId() { return id; } public int getExempt() { return exempt; } public int getNumber_claim() { return number_claim; } public String getInspektor() { return inspektor; } public String getDate_repair() { return date_repair; } public int getPhone_cost() { return phone_cost; } public String getCall() { return call; } }
ID Name Adress Phone Phone adress Cost Exempt type Exempt Date claim Number of claim Inspektor Date repair Phone cost Call
<%=row.getId()%> <%=row.getName()%> <%=row.getAddress()%> <%=row.getPhone()%> <%=row.getPhone_adress%> <%=row.getCost()%> <%=row.getExempt_type()%> <%=row.getExempt()%> <%=row.getDate_claim()%> <%=row.getNumber_claim()%> <%=row.getInspektor()%> <%=row.getDate_repair()%> <%=row.getPhone_cost()%> <%=row.getCall()%>