Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
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
java_dzienna_15_09
Commits
b7af9ff1
Commit
b7af9ff1
authored
Sep 16, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WypiszKraje
parent
53fbe75e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
WypiszKraje.java
...yDanych/src/main/java/zajecia/postgresql/WypiszKraje.java
+28
-0
No files found.
PC24-BazyDanych/src/main/java/zajecia/postgresql/WypiszKraje.java
0 → 100644
View file @
b7af9ff1
package
zajecia
.
postgresql
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
public
class
WypiszKraje
{
public
static
void
main
(
String
[]
args
)
{
// W bazie hr znajduje się tabela countries z kolumnami country_id i country_name
// wypisz wszystkie kraje, obie kolumny
// jeśli umiesz, posortuj alfabetycznie
try
(
Connection
c
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost/hr"
,
"kurs"
,
"abc123"
);
PreparedStatement
stmt
=
c
.
prepareStatement
(
"SELECT * FROM countries ORDER BY country_name"
);
ResultSet
rs
=
stmt
.
executeQuery
())
{
while
(
rs
.
next
())
{
String
countryId
=
rs
.
getString
(
"country_id"
);
String
countryName
=
rs
.
getString
(
"country_name"
);
System
.
out
.
println
(
countryId
+
" "
+
countryName
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
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