Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230617
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
javab_20230617
Commits
7d34f8e3
Commit
7d34f8e3
authored
Jul 02, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Products0 - odczyt produktów z bazy
parent
38442b31
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
Products0.java
PC24-SklepWeb/src/main/java/sklep/web/Products0.java
+21
-0
No files found.
PC24-SklepWeb/src/main/java/sklep/web/Products0.java
View file @
7d34f8e3
...
...
@@ -2,6 +2,11 @@ package sklep.web;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.annotation.WebServlet
;
...
...
@@ -18,6 +23,22 @@ public class Products0 extends HttpServlet {
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
out
.
println
(
"Zaraz odczytam produkty z bazy..."
);
final
String
url
=
"jdbc:postgresql://localhost/sklep"
;
final
String
sql
=
"SELECT * FROM products"
;
try
(
Connection
c
=
DriverManager
.
getConnection
(
url
,
"kurs"
,
"abc123"
);
Statement
stmt
=
c
.
createStatement
();
ResultSet
rs
=
stmt
.
executeQuery
(
sql
))
{
while
(
rs
.
next
())
{
out
.
printf
(
"Produkt nr %s to jest %s za cenę %s\n"
,
rs
.
getInt
(
"product_id"
),
rs
.
getString
(
"product_name"
),
rs
.
getBigDecimal
(
"price"
));
}
}
catch
(
SQLException
e
)
{
out
.
println
(
"Wielka bieda!"
);
e
.
printStackTrace
(
out
);
}
}
}
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