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
3f084f4e
Commit
3f084f4e
authored
Jun 12, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
properties
parent
f99af8fa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
1 deletions
+50
-1
DBConnection.java
PC24-SklepWeb/src/main/java/sklep/db/DBConnection.java
+1
-1
Products1.java
PC24-SklepWeb/src/main/java/sklep/web/Products1.java
+40
-0
sklep.properties
PC24-SklepWeb/src/main/resources/sklep.properties
+9
-0
No files found.
PC24-SklepWeb/src/main/java/sklep/db/DBConnection.java
View file @
3f084f4e
...
...
@@ -32,7 +32,7 @@ public class DBConnection implements AutoCloseable {
public
static
DBConnection
openLocalhost
()
throws
DBException
{
try
{
Connection
c
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost/sklep"
,
"
kurs
"
,
"abc123"
);
Connection
c
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost/sklep"
,
"
alx
"
,
"abc123"
);
c
.
setAutoCommit
(
false
);
return
new
DBConnection
(
c
);
}
catch
(
SQLException
e
)
{
...
...
PC24-SklepWeb/src/main/java/sklep/web/Products1.java
0 → 100644
View file @
3f084f4e
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
);
}
}
}
PC24-SklepWeb/src/main/resources/sklep.properties
0 → 100644
View file @
3f084f4e
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
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