Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_mszczonow_2
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_2
Commits
e60d927f
Commit
e60d927f
authored
Jul 25, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Odczyt wg ID interaktywny
parent
e9a3f138
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
P01_OdczytajWgId.java
src/main/java/programy/P01_OdczytajWgId.java
+19
-4
No files found.
src/main/java/programy/P01_OdczytajWgId.java
View file @
e60d927f
package
programy
;
package
programy
;
import
java.util.Scanner
;
import
jakarta.persistence.EntityManager
;
import
jakarta.persistence.EntityManager
;
import
jakarta.persistence.EntityManagerFactory
;
import
jakarta.persistence.EntityManagerFactory
;
import
jakarta.persistence.Persistence
;
import
jakarta.persistence.Persistence
;
import
model.Department
;
import
model.Employee
;
import
model.Employee
;
public
class
P01_OdczytajWgId
{
public
class
P01_OdczytajWgId
{
...
@@ -12,17 +15,29 @@ public class P01_OdczytajWgId {
...
@@ -12,17 +15,29 @@ public class P01_OdczytajWgId {
EntityManagerFactory
emf
=
Persistence
.
createEntityManagerFactory
(
"hr_postgresql"
);
EntityManagerFactory
emf
=
Persistence
.
createEntityManagerFactory
(
"hr_postgresql"
);
EntityManager
em
=
emf
.
createEntityManager
();
EntityManager
em
=
emf
.
createEntityManager
();
System
.
out
.
println
(
"Mam EntityManagera: "
+
em
);
System
.
out
.
println
(
"Mam EntityManagera: "
+
em
);
Integer
id
=
103
;
Scanner
sc
=
new
Scanner
(
System
.
in
);
while
(
true
)
{
System
.
out
.
print
(
"Podaj ID pracownika (0 kończy program): "
);
Integer
id
=
sc
.
nextInt
();
if
(
id
==
0
)
break
;
Employee
emp
=
em
.
find
(
Employee
.
class
,
id
);
Employee
emp
=
em
.
find
(
Employee
.
class
,
id
);
System
.
out
.
println
(
"Odczytany obiekt: "
+
emp
);
System
.
out
.
println
(
"Odczytany obiekt: "
+
emp
);
if
(
emp
!=
null
)
{
if
(
emp
==
null
)
{
System
.
out
.
printf
(
"Nie ma pracownika o id %d\n"
,
id
);
continue
;
}
System
.
out
.
printf
(
"%s %s (%s) zarabia %s\n"
,
System
.
out
.
printf
(
"%s %s (%s) zarabia %s\n"
,
emp
.
getFirstName
(),
emp
.
getLastName
(),
emp
.
getJob
().
getJobTitle
(),
emp
.
getSalary
());
emp
.
getFirstName
(),
emp
.
getLastName
(),
emp
.
getJob
().
getJobTitle
(),
emp
.
getSalary
());
Department
dep
=
emp
.
getDepartment
();
if
(
dep
!=
null
)
{
System
.
out
.
printf
(
"Departament %s, %s, %s, %s\n"
,
dep
.
getDepartmentName
(),
dep
.
getLocation
().
getStreetAddress
(),
dep
.
getLocation
().
getCity
(),
dep
.
getLocation
().
getCountry
().
getCountryName
());
}
}
}
sc
.
close
();
em
.
close
();
em
.
close
();
emf
.
close
();
emf
.
close
();
System
.
out
.
println
(
"Koniec"
);
System
.
out
.
println
(
"Koniec"
);
...
...
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