Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_mszczonow_1
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
alx_mszczonow_1
Commits
73255e46
Commit
73255e46
authored
Jul 24, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PolaczPostgres1
parent
cfd4b9fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
pom.xml
pom.xml
+7
-0
PolaczPostgres1.java
src/main/java/bazy/a_poczatek/PolaczPostgres1.java
+35
-0
No files found.
pom.xml
View file @
73255e46
...
@@ -31,5 +31,11 @@
...
@@ -31,5 +31,11 @@
<version>
5.9.3
</version>
<version>
5.9.3
</version>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
<version>
42.6.0
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
src/main/java/bazy/a_poczatek/PolaczPostgres1.java
0 → 100644
View file @
73255e46
package
bazy
.
a_poczatek
;
import
java.math.BigDecimal
;
import
java.sql.*
;
public
class
PolaczPostgres1
{
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
Connection
c
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost/hr"
,
"kurs"
,
"abc123"
);
System
.
out
.
println
(
"Mam połączenie: "
+
c
);
Statement
stmt
=
c
.
createStatement
();
ResultSet
rs
=
stmt
.
executeQuery
(
"SELECT * FROM employees"
);
System
.
out
.
println
(
"ResultSet: "
+
rs
);
while
(
rs
.
next
())
{
// odczyt wg numerów kolumn, numeracja od 1
int
id
=
rs
.
getInt
(
1
);
String
firstName
=
rs
.
getString
(
2
);
String
lastName
=
rs
.
getString
(
3
);
// odczyt wg nazw kolumn:
String
job
=
rs
.
getString
(
"job_id"
);
BigDecimal
salary
=
rs
.
getBigDecimal
(
"salary"
);
System
.
out
.
printf
(
"%d: %s %s (%s) zarabia %s\n"
,
id
,
firstName
,
lastName
,
job
,
salary
);
// dobrą praktyką jest zamykanie zasobów ResultSet i Statement - bo serwer SQL może trzymać dla nas jakieś zasoby
rs
.
close
();
stmt
.
close
();
c
.
close
();
}
}
}
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