Commit 93589288 by Bogdan Andjelkovic

oglas procedure bogdan

parent 1f9a64b0
......@@ -71,7 +71,7 @@ public class OglasController
}
model.addAttribute("oglasi",listaOglasa);
List<String> list = new ArrayList<String>();
for (Oglas o:oRepo.findAll()) {
for (Oglas o:listaOglasa) {
list.add(kRepo.findCity(o.getLokacijaId()));
}
model.addAttribute("gradovi",list);
......@@ -114,6 +114,6 @@ public class OglasController
list.add(kRepo.findCity(o.getLokacijaId()));
}
model.addAttribute("gradovi",list);
return "/lista-oglasa";
return "lista-oglasa";
}
}
......@@ -59,30 +59,15 @@ public class OglasRepository
}
public List<Oglas> findAll( )
{
List<Oglas> list = new ArrayList<Oglas>();
String sql = "select * from oglas";
ResultSet rs = null;
try {
rs = dataBase.statement.executeQuery( sql);
while( rs.next())
{
Oglas oglas = new Oglas( rs.getInt("oglasId"), rs.getInt("korisnikId"), rs.getString("naslov"),rs.getString("opis"),rs.getInt("lokacijaId"),rs.getDouble("cena"),rs.getInt("vrstaOglasaId"),rs.getDouble("kvadratura"),rs.getInt("brojSoba"),rs.getBoolean("namesten"),rs.getBoolean("grejanje"),rs.getBoolean("lift"),rs.getString("lokacija"));
list.add( oglas);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return( list);
}
public Oglas findById(int oglasId)
{
String sql = "select * from oglas where oglasid = " + oglasId;
String sql = "{ call findOglasbyId(?)}";
CallableStatement stmt = null;
ResultSet rs = null;
try {
rs = dataBase.statement.executeQuery( sql);
stmt = dataBase.connection.prepareCall( sql);
stmt.setInt( 1, oglasId);
rs = stmt.executeQuery();
while( rs.next())
{
Oglas oglas = new Oglas( rs.getInt("oglasId"), rs.getInt("korisnikId"), rs.getString("naslov"),rs.getString("opis"),rs.getInt("lokacijaId"),rs.getDouble("cena"),rs.getInt("vrstaOglasaId"),rs.getDouble("kvadratura"),rs.getInt("brojSoba"),rs.getBoolean("namesten"),rs.getBoolean("grejanje"),rs.getBoolean("lift"),rs.getString("lokacija"));
......@@ -94,30 +79,15 @@ public class OglasRepository
return( null);
}
public List<Oglas> findAllByKorisnikId( int korisnikId)
{
List<Oglas> list = new ArrayList<Oglas>();
String sql = "select * from oglas where korisnikid = " + korisnikId;
ResultSet rs = null;
try {
rs = dataBase.statement.executeQuery( sql);
while( rs.next())
{
Oglas oglas = new Oglas( rs.getInt("oglasId"), rs.getInt("korisnikId"), rs.getString("naslov"),rs.getString("opis"),rs.getInt("lokacijaId"),rs.getDouble("cena"),rs.getInt("vrstaOglasaId"),rs.getDouble("kvadratura"),rs.getInt("brojSoba"),rs.getBoolean("namesten"),rs.getBoolean("grejanje"),rs.getBoolean("lift"),rs.getString("lokacija"));
list.add( oglas);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return( list);
}
public void deleteOglasi(Integer id)
{
String sql = "select * from oglas where korisnikid = " + id;
String sql = "{call findAllByKorisnikId(?)}";
CallableStatement stmt = null;
ResultSet rs = null;
try {
rs = dataBase.statement.executeQuery( sql);
stmt = dataBase.connection.prepareCall( sql);
stmt.setInt(1,id);
rs = stmt.executeQuery();
while( rs.next())
{
int oglasid = rs.getInt("oglasid");
......@@ -127,9 +97,12 @@ public class OglasRepository
throw new RuntimeException(e);
}
sql = "delete from oglas where KorisnikId = "+id;
sql = "{call deleteOglasiByKorisnikId(?)}";
CallableStatement stmt1 = null;
try {
dataBase.statement.execute(sql);
stmt1 = dataBase.connection.prepareCall( sql);
stmt1.setInt(1, id);
stmt1.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment