package ru.aserdyuchenko.crudServlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Anton Serdyuchenko. anton415@gmail.com
 */
public class UsersServlet extends HttpServlet {
    private static final Logger log = LoggerFactory.getLogger(UsersServlet.class);

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter writer = new PrintWriter(response.getOutputStream());
        try {
            Class.forName("org.postgresql.Driver");
            Settings settings = Settings.getInstance();
            Connection connection = DriverManager.getConnection(
                    "jdbc:postgresql://127.0.0.1:5432/sqlite",
                    "anton",
                    "password");
            PreparedStatement ps = connection.prepareStatement("SELECT * FROM users");
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery("SELECT * FROM users");
            Map<String, User> users = new HashMap<>();
            while (rs.next()) {
                users.put(rs.getString("login"), new User(rs.getString("name"), rs.getString("email"), rs.getString("createDate")));
            }
            writer.append(users.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        writer.flush();
    }
/*
    @Override
    protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        try {
            this.storage.add(request.getParameter("login"), request.getParameter("name"), request.getParameter("email"), request.getParameter("createDate"));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        doGet(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        this.users.put(request.getParameter("login"), new User(request.getParameter("name"), request.getParameter("email"), request.getParameter("createDate")));
        doGet(request, response);
    }

    @Override
    protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        this.users.remove(request.getParameter("login"));
        doGet(request, response);
    }
*/

}

@@ -321,27 +321,8 @@
 er;%0A
-import java.sql.*;%0A
 impo
@@ -343,16 +343,16 @@
 ashMap;%0A
+
 import j
@@ -895,699 +895,92 @@
    S
-ettings settings = Settings.getInstance();%0A            Connection connection = DriverManager.getConnection(%0A                    %22jdbc:postgresql://127.0.0.1:5432/sqlite%22,%0A                    %22anton%22,%0A                    %22password%22);%0A            PreparedStatement ps = connection.prepareStatement(%22SELECT * FROM users%22);%0A            Statement statement = connection.createStatement();%0A            ResultSet rs = statement.executeQuery(%22SELECT * FROM users%22);%0A            Map%3CString, User%3E users = new HashMap%3C%3E();%0A            while (rs.next()) %7B%0A                users.put(rs.getString(%22login%22), new User(rs.getString(%22name%22), rs.getString(%22email%22), rs.getString(%22createDate%22)));%0A            %7D
+torage storage = new Storage();%0A            Map%3CString, User%3E users = storage.get();
 %0A   

Change connection from servlet to jdbc storage. Now servlet connect to DB using Storage.java.