source: src/main/java/com/example/cookbook/repository/SostojkiRespository.java

Last change on this file was 501396e, checked in by Blazho <aleksandar.blazhevski@…>, 9 months ago

added missing files

  • Property mode set to 100644
File size: 1.4 KB
Line 
1package com.example.cookbook.repository;
2
3
4import com.example.cookbook.dbConfig.DB;
5import com.example.cookbook.model.Slika;
6import com.example.cookbook.model.Sostojka;
7import org.springframework.stereotype.Repository;
8
9import java.nio.charset.StandardCharsets;
10import java.sql.Connection;
11import java.sql.PreparedStatement;
12import java.sql.ResultSet;
13import java.sql.SQLException;
14import java.util.ArrayList;
15import java.util.List;
16
17@Repository
18public class SostojkiRespository {
19
20
21 public List<Sostojka> findAllByRId(Long rId) throws SQLException {
22 Connection connection = DB.getConnection();
23
24 String query = "select s.s_id, s_naziv\n" +
25 "from sodrzi\n" +
26 " left join sostojki s on\n" +
27 " sodrzi.s_id = s.s_id\n" +
28 "where rec_id = ?";
29
30 PreparedStatement prepStm = connection.prepareStatement(query);
31 prepStm.setLong(1, rId);
32
33 ResultSet result = prepStm.executeQuery();
34 List<Sostojka> sostojki = new ArrayList<>();
35
36 while (result.next()){
37 Sostojka sostojka = new Sostojka();
38 sostojka.setsId(result.getLong("s_id"));
39 sostojka.setsNaziv(result.getString("s_naziv"));
40 sostojki.add(sostojka);
41 }
42
43 result.close();
44 prepStm.close();
45 DB.closeConnection();
46
47 return sostojki;
48 }
49}
Note: See TracBrowser for help on using the repository browser.