Ignore:
Timestamp:
02/04/24 17:12:57 (9 months ago)
Author:
Blazho <aleksandar.blazhevski@…>
Branches:
master
Children:
a226bc3
Parents:
cab1b7d
Message:

Added order items page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/cookbook/repository/NarackiRepository.java

    rcab1b7d ree27685  
    44import com.example.cookbook.dbConfig.DB;
    55import com.example.cookbook.model.Naracka;
     6import com.example.cookbook.model.Recept;
     7import com.example.cookbook.model.Stavka;
    68import org.springframework.stereotype.Repository;
    79
    8 import java.sql.Connection;
    9 import java.sql.ResultSet;
    10 import java.sql.SQLException;
    11 import java.sql.Statement;
     10import java.sql.*;
    1211import java.time.LocalDateTime;
    1312import java.util.ArrayList;
     
    3938        return naracki;
    4039    }
     40
     41    public List<Stavka> findByTelAndVreme(String telefon, LocalDateTime vreme) throws SQLException {
     42
     43        Connection connection = DB.getConnection();
     44        String query = "select sk.vreme, sk.telefon, r.rec_ime, nacin from so_koi sk\n" +
     45                "        left join recepti r on r.rec_id = sk.rec_id\n" +
     46                "where vreme = ? and telefon = ?;";
     47        PreparedStatement prepStm = connection.prepareStatement(query);
     48
     49        prepStm.setObject(1, vreme);
     50        prepStm.setString(2, telefon);
     51
     52        ResultSet result = prepStm.executeQuery();
     53        List<Stavka> stavki = new ArrayList<>();
     54        while (result.next()){
     55            Stavka stavka = new Stavka();
     56            stavka.setRecIme(result.getString("rec_ime"));
     57            stavka.setTelefon(result.getString("telefon"));
     58            stavka.setNacin(result.getString("nacin"));
     59            stavka.setVreme(result.getObject("vreme", LocalDateTime.class));
     60            stavki.add(stavka);
     61        }
     62        DB.closeConnection();
     63        result.close();
     64        prepStm.close();
     65        return stavki;
     66    }
    4167}
Note: See TracChangeset for help on using the changeset viewer.