Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20250331
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
20250331
Commits
b047b539
Commit
b047b539
authored
Apr 07, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pierwszy program postgresql
parent
437b5282
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
5 deletions
+58
-5
pom.xml
pom.xml
+13
-2
OdczytajPostgreSQL1.java
src/main/java/bazy/zajecia/OdczytajPostgreSQL1.java
+34
-0
C13_MultiMap.java
.../gotowe/p31_streamy/c_przeglad_operacji/C13_MultiMap.java
+5
-0
ProstyCzas.java
src/main/java/gotowe/p35_daty/ProstyCzas.java
+6
-2
Kopiuj1.java
src/main/java/gotowe/p40_io/Kopiuj1.java
+0
-1
No files found.
pom.xml
View file @
b047b539
...
...
@@ -6,11 +6,21 @@
<groupId>
org.example
</groupId>
<artifactId>
SzkolenieJavaXTB
</artifactId>
<version>
1.
0
</version>
<version>
1.
1-SNAPSHOT
</version>
<properties>
<maven.compiler.release>
21
</maven.compiler.release>
<maven.compiler.source>
21
</maven.compiler.source>
<maven.compiler.target>
21
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
<version>
42.7.5
</version>
<scope>
runtime
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/main/java/bazy/zajecia/OdczytajPostgreSQL1.java
0 → 100644
View file @
b047b539
package
bazy
.
zajecia
;
import
java.sql.*
;
public
class
OdczytajPostgreSQL1
{
public
static
void
main
(
String
[]
args
)
{
// JDBC - Java Database Connectivity
String
url
=
"jdbc:postgresql://localhost:5432/hr"
;
try
(
Connection
c
=
DriverManager
.
getConnection
(
url
,
"alx"
,
"abc123"
))
{
System
.
out
.
println
(
"Udało się połączyć: "
+
c
);
// Gdyby zależność była w zakresie compile, a nie runtime, moglibyśmy skorzystać z klas zawartych w bibliotece...
// org.postgresql.jdbc.PgConnection pgConnection = (org.postgresql.jdbc.PgConnection)c;
// int pid = pgConnection.getBackendPID();
// System.out.println(pid);
try
(
PreparedStatement
stmt
=
c
.
prepareStatement
(
"SELECT * FROM employees ORDER BY employee_id"
);
ResultSet
rs
=
stmt
.
executeQuery
())
{
System
.
out
.
println
(
"ResultSet: "
+
rs
);
while
(
rs
.
next
())
{
System
.
out
.
printf
(
"Pracownik nr %d: %s %s (%s), pensja %s%n"
,
rs
.
getInt
(
1
),
rs
.
getString
(
"first_name"
),
rs
.
getString
(
"last_name"
),
rs
.
getString
(
"job_id"
),
rs
.
getBigDecimal
(
"salary"
)
);
}
}
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
src/main/java/gotowe/p31_streamy/c_przeglad_operacji/C13_MultiMap.java
View file @
b047b539
...
...
@@ -25,6 +25,11 @@ public class C13_MultiMap {
}
})
.
forEach
(
x
->
System
.
out
.
print
(
x
+
" | "
));
System
.
out
.
println
(
"================="
);
// przykład mapowania 1→1 za pomocą mapMulti (wiadomo, że dałoby się zwykłym map)
Stream
.
of
(
1
,
3
,
0
,
5
)
.
mapMulti
((
n
,
c
)
->
c
.
accept
(
n
*
n
))
.
forEach
(
x
->
System
.
out
.
print
(
x
+
" , "
));
}
}
src/main/java/gotowe/p35_daty/ProstyCzas.java
View file @
b047b539
...
...
@@ -5,7 +5,6 @@ import java.time.LocalTime;
public
class
ProstyCzas
{
public
static
void
main
(
String
[]
args
)
{
LocalTime
czas1
=
LocalTime
.
now
();
// ustawia z dokladnoscia do milisekundy
System
.
out
.
println
(
czas1
);
...
...
@@ -15,7 +14,12 @@ public class ProstyCzas {
LocalTime
czas3
=
LocalTime
.
of
(
12
,
15
,
33
);
System
.
out
.
println
(
czas3
);
// nie ma setterów
// czas3.setHour(14);
// ale można zmienić wartość pola i pobrać NOWY obiekt
czas3
=
czas3
.
withHour
(
14
);
System
.
out
.
println
(
czas3
);
// uwaga: nanosekumdy podajemy jako liczbę całkowitą (int)
LocalTime
czas4
=
LocalTime
.
of
(
12
,
15
,
33
,
333222111
);
System
.
out
.
println
(
czas4
);
...
...
src/main/java/gotowe/p40_io/Kopiuj1.java
View file @
b047b539
...
...
@@ -38,7 +38,6 @@ public class Kopiuj1 {
}
public
static
void
main
(
String
[]
args
)
{
long
start
=
System
.
currentTimeMillis
();
kopiuj
(
"pliki/pan_tadeusz.txt"
,
"kopia1.txt"
);
long
koniec
=
System
.
currentTimeMillis
();
...
...
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