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 | |
---|
1 | package com.example.cookbook.repository;
|
---|
2 |
|
---|
3 |
|
---|
4 | import com.example.cookbook.dbConfig.DB;
|
---|
5 | import com.example.cookbook.model.Slika;
|
---|
6 | import com.example.cookbook.model.Sostojka;
|
---|
7 | import org.springframework.stereotype.Repository;
|
---|
8 |
|
---|
9 | import java.nio.charset.StandardCharsets;
|
---|
10 | import java.sql.Connection;
|
---|
11 | import java.sql.PreparedStatement;
|
---|
12 | import java.sql.ResultSet;
|
---|
13 | import java.sql.SQLException;
|
---|
14 | import java.util.ArrayList;
|
---|
15 | import java.util.List;
|
---|
16 |
|
---|
17 | @Repository
|
---|
18 | public 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.