Commit 3f084f4e by Patryk Czarnik

properties

parent f99af8fa
...@@ -32,7 +32,7 @@ public class DBConnection implements AutoCloseable { ...@@ -32,7 +32,7 @@ public class DBConnection implements AutoCloseable {
public static DBConnection openLocalhost() throws DBException { public static DBConnection openLocalhost() throws DBException {
try { try {
Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/sklep", "kurs", "abc123"); Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/sklep", "alx", "abc123");
c.setAutoCommit(false); c.setAutoCommit(false);
return new DBConnection(c); return new DBConnection(c);
} catch (SQLException e) { } catch (SQLException e) {
......
package sklep.web;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import sklep.db.DBConnection;
import sklep.db.DBException;
import sklep.db.ProductDAO;
import sklep.model.Product;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
@WebServlet("/products1")
public class Products1 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest requets, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
out.println("Zaraz odczytam produkty z bazy...");
try(DBConnection c = DBConnection.open()) {
ProductDAO productDAO = c.productDAO();
List<Product> products = productDAO.readAll();
for(Product p : products) {
out.printf("Produkt nr %d to jest %s za cenę %s\n",
p.getProductId(), p.getProductName(), p.getPrice());
}
} catch (DBException e) {
out.println("Bład: " + e);
e.printStackTrace(out);
}
}
}
url=jdbc:postgresql://localhost:5432/sklep
driver_class=org.postgresql.Driver
user=alx
password=abc123
photo_dir=/home/patryk/sklep/foto
# Sciezki na Windows: albo piszemy slashe / , albo podwojne backslashe \\
# photo_dir=C:/Users/Patryk/Desktop/sklep/foto
# photo_dir=C:\\Users\\Patryk\\Desktop\\sklep\\foto
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment