Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230928
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_20230928
Commits
1dbb4288
Commit
1dbb4288
authored
Oct 18, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
products0
parent
0a6a295f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
+49
-0
pom.xml
PC25-SklepWeb/pom.xml
+6
-0
Products0.java
PC25-SklepWeb/src/main/java/sklep/web/Products0.java
+43
-0
No files found.
PC25-SklepWeb/pom.xml
View file @
1dbb4288
...
@@ -19,6 +19,12 @@
...
@@ -19,6 +19,12 @@
<version>
10.0.0
</version>
<version>
10.0.0
</version>
<scope>
provided
</scope>
<scope>
provided
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
<version>
42.6.0
</version>
<scope>
runtime
</scope>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
PC25-SklepWeb/src/main/java/sklep/web/Products0.java
0 → 100644
View file @
1dbb4288
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
;
import
jakarta.servlet.http.HttpServlet
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
@WebServlet
(
"/products0"
)
public
class
Products0
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..."
);
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