Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SkuciSe
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tim 2 - 2022
SkuciSe
Commits
dc175993
Commit
dc175993
authored
Sep 07, 2022
by
Milovan Samardzic
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
1b1fa94d
01f715be
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
28 deletions
+45
-28
SkuciSe/src/main/java/com/example/SkuciSe/repository/KorisnikRepository.java
+16
-1
SkuciSe/src/main/java/com/example/SkuciSe/repository/OglasRepository.java
+29
-27
No files found.
SkuciSe/src/main/java/com/example/SkuciSe/repository/KorisnikRepository.java
View file @
dc175993
...
@@ -117,7 +117,7 @@ public class KorisnikRepository
...
@@ -117,7 +117,7 @@ public class KorisnikRepository
public
List
<
Korisnik
>
findAll
()
public
List
<
Korisnik
>
findAll
()
{
{
String
sql
=
"select * from korisnik where TipID = 1"
;
/*
String sql = "select * from korisnik where TipID = 1";
List<Korisnik> list = new ArrayList<Korisnik>();
List<Korisnik> list = new ArrayList<Korisnik>();
ResultSet rs = null;
ResultSet rs = null;
try {
try {
...
@@ -129,6 +129,21 @@ public class KorisnikRepository
...
@@ -129,6 +129,21 @@ public class KorisnikRepository
}
}
catch (SQLException e) {
catch (SQLException e) {
throw new RuntimeException(e);
throw new RuntimeException(e);
}*/
CallableStatement
stmt
=
null
;
ResultSet
rs
=
null
;
try
{
String
sql
=
"{ call findAllKorisnik}"
;
stmt
=
dataBase
.
connection
.
prepareCall
(
sql
);
List
<
Korisnik
>
list
=
new
ArrayList
<
Korisnik
>();
rs
=
stmt
.
executeQuery
();
while
(
rs
.
next
())
{
list
.
add
(
new
Korisnik
(
rs
.
getInt
(
"korisnikId"
),
rs
.
getString
(
"ime"
),
rs
.
getString
(
"prezime"
),
rs
.
getString
(
"email"
),
rs
.
getString
(
"sifra"
),
rs
.
getString
(
"telefon"
),
rs
.
getString
(
"slika"
),
rs
.
getInt
(
"tipid"
),
rs
.
getInt
(
"gradid"
),
rs
.
getBoolean
(
"enabled"
)));
}
return
list
;
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
}
...
...
SkuciSe/src/main/java/com/example/SkuciSe/repository/OglasRepository.java
View file @
dc175993
...
@@ -6,8 +6,7 @@ import org.springframework.stereotype.Component;
...
@@ -6,8 +6,7 @@ import org.springframework.stereotype.Component;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.sql.SQLException
;
import
java.sql.*
;
import
java.sql.Statement
;
import
java.util.Base64
;
import
java.util.Base64
;
@Component
@Component
...
@@ -19,33 +18,36 @@ public class OglasRepository
...
@@ -19,33 +18,36 @@ public class OglasRepository
public
void
insert
(
int
korisnikId
,
Oglas
newOglas
,
MultipartFile
[]
files
)
public
void
insert
(
int
korisnikId
,
Oglas
newOglas
,
MultipartFile
[]
files
)
{
{
int
oglasId
;
int
oglasId
;
String
sql
=
"insert into oglas( korisnikID, naslov, opis, lokacijaId, cena, vrstaoglasaid, kvadratura, brojsoba, namesten, grejanje, lift, lokacija)"
+
//String sql = "{ call insertOglas(?,?,?,?,?,?,?,?,?,?,?,?)}";
"values ( "
+
korisnikId
+
String
sql
=
"insert into oglas( korisnikID, naslov, opis, lokacijaId, cena, vrstaoglasaid, kvadratura, brojsoba, namesten, grejanje, lift, lokacija) values(?,?,?,?,?,?,?,?,?,?,?,?);"
;
", '"
+
newOglas
.
getNaslov
()
+
PreparedStatement
stmt
=
null
;
"','"
+
newOglas
.
getOpis
()
+
"',"
+
newOglas
.
getLokacijaId
()
+
","
+
newOglas
.
getCena
()
+
","
+
newOglas
.
getVrstaOglasaId
()
+
","
+
newOglas
.
getKvadratura
()
+
","
+
newOglas
.
getBrojSoba
()
+
","
+
newOglas
.
isNamesten
()
+
","
+
newOglas
.
isGrejanje
()
+
","
+
newOglas
.
isLift
()
+
",'"
+
newOglas
.
getLokacija
()
+
"')"
;
System
.
out
.
println
(
sql
);
try
{
try
{
oglasId
=
dataBase
.
statement
.
executeUpdate
(
sql
,
Statement
.
RETURN_GENERATED_KEYS
);
stmt
=
dataBase
.
connection
.
prepareStatement
(
sql
,
Statement
.
RETURN_GENERATED_KEYS
);
System
.
out
.
println
(
oglasId
);
stmt
.
setInt
(
1
,
korisnikId
);
stmt
.
setString
(
2
,
newOglas
.
getNaslov
());
for
(
MultipartFile
file:
files
)
stmt
.
setString
(
3
,
newOglas
.
getOpis
());
{
stmt
.
setInt
(
4
,
newOglas
.
getLokacijaId
());
sql
=
"insert into Slike( oglasid, slika)"
;
stmt
.
setDouble
(
5
,
newOglas
.
getCena
());
String
filename
=
Base64
.
getEncoder
().
encodeToString
(
file
.
getBytes
());
stmt
.
setInt
(
6
,
newOglas
.
getVrstaOglasaId
());
sql
+=
" values ("
+
oglasId
+
",'"
+
filename
+
"')"
;
stmt
.
setDouble
(
7
,
newOglas
.
getKvadratura
());
dataBase
.
statement
.
executeUpdate
(
sql
);
stmt
.
setInt
(
8
,
newOglas
.
getBrojSoba
());
stmt
.
setBoolean
(
9
,
newOglas
.
isNamesten
());
stmt
.
setBoolean
(
10
,
newOglas
.
isGrejanje
());
stmt
.
setBoolean
(
11
,
newOglas
.
isLift
());
stmt
.
setString
(
12
,
newOglas
.
getLokacija
());
stmt
.
addBatch
();
stmt
.
executeBatch
();
ResultSet
rs
=
stmt
.
getGeneratedKeys
();
if
(
rs
.
next
())
{
oglasId
=
rs
.
getInt
(
1
);
for
(
MultipartFile
file:
files
)
{
sql
=
"insert into Slike( oglasid, slika)"
;
String
filename
=
Base64
.
getEncoder
().
encodeToString
(
file
.
getBytes
());
sql
+=
" values ("
+
oglasId
+
",'"
+
filename
+
"')"
;
dataBase
.
statement
.
executeUpdate
(
sql
);
}
}
}
System
.
out
.
println
(
"slike inserted"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
...
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