source: src/main/java/com/example/cookbook/repository/NarackiRepository.java@ ee27685

Last change on this file since ee27685 was ee27685, checked in by Blazho <aleksandar.blazhevski@…>, 5 months ago

Added order items page

  • Property mode set to 100644
File size: 2.2 KB
Line 
1package com.example.cookbook.repository;
2
3
4import com.example.cookbook.dbConfig.DB;
5import com.example.cookbook.model.Naracka;
6import com.example.cookbook.model.Recept;
7import com.example.cookbook.model.Stavka;
8import org.springframework.stereotype.Repository;
9
10import java.sql.*;
11import java.time.LocalDateTime;
12import java.util.ArrayList;
13import java.util.List;
14
15@Repository
16public class NarackiRepository {
17
18
19 public List<Naracka> findAll() throws SQLException {
20
21 Connection connection = DB.getConnection();
22 Statement stm = connection.createStatement();
23 String query = "select vreme, telefon from naracki;";
24
25 ResultSet result = stm.executeQuery(query);
26 List<Naracka> naracki = new ArrayList<>();
27
28 while (result.next()){
29 Naracka naracka = new Naracka();
30 naracka.setVreme(result.getObject("vreme", LocalDateTime.class));
31 naracka.setTelefon(result.getString("telefon"));
32 naracki.add(naracka);
33 }
34
35 DB.closeConnection();
36 result.close();
37 stm.close();
38 return naracki;
39 }
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 }
67}
Note: See TracBrowser for help on using the repository browser.