Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20240528-BJava
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
20240528-BJava
Commits
c7a525a8
Commit
c7a525a8
authored
Jun 12, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Products2
parent
3f084f4e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
2 deletions
+51
-2
ZwyklyOdczyt_JDBC.java
PC24-SklepWeb/src/main/java/sklep/db/ZwyklyOdczyt_JDBC.java
+1
-1
Products1.java
PC24-SklepWeb/src/main/java/sklep/web/Products1.java
+0
-1
Products2.java
PC24-SklepWeb/src/main/java/sklep/web/Products2.java
+50
-0
No files found.
PC24-SklepWeb/src/main/java/sklep/db/ZwyklyOdczyt_JDBC.java
View file @
c7a525a8
...
...
@@ -11,7 +11,7 @@ public class ZwyklyOdczyt_JDBC {
public
static
void
main
(
String
[]
args
)
{
String
url
=
"jdbc:postgresql://localhost:5432/sklep"
;
String
sql
=
"SELECT * FROM products"
;
try
(
Connection
c
=
DriverManager
.
getConnection
(
url
,
"
kurs
"
,
"abc123"
);
try
(
Connection
c
=
DriverManager
.
getConnection
(
url
,
"
alx
"
,
"abc123"
);
PreparedStatement
stmt
=
c
.
prepareStatement
(
sql
);
ResultSet
rs
=
stmt
.
executeQuery
())
{
...
...
PC24-SklepWeb/src/main/java/sklep/web/Products1.java
View file @
c7a525a8
...
...
@@ -27,7 +27,6 @@ public class Products1 extends HttpServlet {
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
());
...
...
PC24-SklepWeb/src/main/java/sklep/web/Products2.java
0 → 100644
View file @
c7a525a8
package
sklep
.
web
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.List
;
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
;
@WebServlet
(
"/products2"
)
public
class
Products2
extends
HttpServlet
{
@Override
protected
void
doGet
(
HttpServletRequest
requets
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
response
.
setContentType
(
"text/html"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
out
.
println
(
"""
<!DOCTYPE html>
<html>
<head>
<title>Lista produktów</title>
<link rel='stylesheet' type='text/css' href='styl.css'>
</head>
<body>
<h1>Produkty</h1>
"""
);
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
List
<
Product
>
products
=
productDAO
.
readAll
();
for
(
Product
product
:
products
)
{
out
.
println
(
product
.
toHtml
());
}
}
catch
(
DBException
e
)
{
out
.
println
(
"Wielka bieda!"
);
out
.
print
(
"<pre>"
);
e
.
printStackTrace
(
out
);
out
.
print
(
"</pre>"
);
}
out
.
println
(
"</body></html>"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment