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
a5311045
Commit
a5311045
authored
Sep 30, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parametry
parent
6b196884
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
0 deletions
+95
-0
Parametry.java
PC27-Hibernate/src/main/java/sklep/przyklady/Parametry.java
+48
-0
ParametryPozycyjne.java
...ate/src/main/java/sklep/przyklady/ParametryPozycyjne.java
+47
-0
No files found.
PC27-Hibernate/src/main/java/sklep/przyklady/Parametry.java
0 → 100644
View file @
a5311045
package
sklep
.
przyklady
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
java.util.Scanner
;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityManagerFactory
;
import
javax.persistence.Persistence
;
import
javax.persistence.TypedQuery
;
import
sklep.model.Product
;
public
class
Parametry
{
public
static
void
main
(
String
[]
args
)
{
EntityManagerFactory
emf
=
null
;
EntityManager
em
=
null
;
try
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
emf
=
Persistence
.
createEntityManagerFactory
(
"sklep"
);
em
=
emf
.
createEntityManager
();
System
.
out
.
print
(
"Podaj minimalną cenę: "
);
BigDecimal
min
=
sc
.
nextBigDecimal
();
System
.
out
.
print
(
"Podaj maksymalną cenę: "
);
BigDecimal
max
=
sc
.
nextBigDecimal
();
TypedQuery
<
Product
>
query
=
em
.
createQuery
(
"SELECT p FROM Product p WHERE p.price BETWEEN :minprice AND :maxprice"
,
Product
.
class
);
query
.
setParameter
(
"minprice"
,
min
);
query
.
setParameter
(
"maxprice"
,
max
);
List
<
Product
>
products
=
query
.
getResultList
();
System
.
out
.
println
(
"Odczytano "
+
products
.
size
()
+
" rekordów:"
);
for
(
Product
product
:
products
)
{
System
.
out
.
println
(
" * "
+
product
.
getProductName
()
+
" za "
+
product
.
getPrice
());
}
}
finally
{
if
(
em
!=
null
)
em
.
close
();
if
(
emf
!=
null
)
emf
.
close
();
}
}
}
PC27-Hibernate/src/main/java/sklep/przyklady/ParametryPozycyjne.java
0 → 100644
View file @
a5311045
package
sklep
.
przyklady
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
java.util.Scanner
;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityManagerFactory
;
import
javax.persistence.Persistence
;
import
javax.persistence.TypedQuery
;
import
sklep.model.Product
;
public
class
ParametryPozycyjne
{
public
static
void
main
(
String
[]
args
)
{
EntityManagerFactory
emf
=
null
;
EntityManager
em
=
null
;
try
{
Scanner
sc
=
new
Scanner
(
System
.
in
);
emf
=
Persistence
.
createEntityManagerFactory
(
"sklep"
);
em
=
emf
.
createEntityManager
();
System
.
out
.
print
(
"Podaj minimalną cenę: "
);
BigDecimal
min
=
sc
.
nextBigDecimal
();
System
.
out
.
print
(
"Podaj maksymalną cenę: "
);
BigDecimal
max
=
sc
.
nextBigDecimal
();
TypedQuery
<
Product
>
query
=
em
.
createQuery
(
"SELECT p FROM Product p WHERE p.price BETWEEN ?1 AND ?2"
,
Product
.
class
);
query
.
setParameter
(
1
,
min
);
query
.
setParameter
(
2
,
max
);
List
<
Product
>
products
=
query
.
getResultList
();
System
.
out
.
println
(
"Odczytano "
+
products
.
size
()
+
" rekordów:"
);
for
(
Product
product
:
products
)
{
System
.
out
.
println
(
" * "
+
product
.
getProductName
()
+
" za "
+
product
.
getPrice
());
}
}
finally
{
if
(
em
!=
null
)
em
.
close
();
if
(
emf
!=
null
)
emf
.
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