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.3 KB
|
Line | |
---|
1 | package com.example.cookbook.repository;
|
---|
2 |
|
---|
3 | import com.example.cookbook.dbConfig.DB;
|
---|
4 | import com.example.cookbook.model.Recept;
|
---|
5 | import com.example.cookbook.model.Slika;
|
---|
6 | import org.springframework.stereotype.Repository;
|
---|
7 |
|
---|
8 | import java.nio.charset.StandardCharsets;
|
---|
9 | import java.sql.Connection;
|
---|
10 | import java.sql.PreparedStatement;
|
---|
11 | import java.sql.ResultSet;
|
---|
12 | import java.sql.SQLException;
|
---|
13 | import java.util.ArrayList;
|
---|
14 | import java.util.List;
|
---|
15 |
|
---|
16 | @Repository
|
---|
17 | public class SlikiZaReceptRepository {
|
---|
18 |
|
---|
19 | public List<Slika> findAllForRecipe(Long recId) throws SQLException {
|
---|
20 | Connection connection = DB.getConnection();
|
---|
21 |
|
---|
22 | String query = "select * from sliki s where s.rec_id = ? order by s.reden_broj asc";
|
---|
23 | PreparedStatement prepStm = connection.prepareStatement(query);
|
---|
24 | prepStm.setLong(1, recId);
|
---|
25 |
|
---|
26 | ResultSet result = prepStm.executeQuery();
|
---|
27 | List<Slika> sliki = new ArrayList<>();
|
---|
28 |
|
---|
29 | while (result.next()){
|
---|
30 | Slika slika = new Slika();
|
---|
31 | slika.setRecId(result.getLong("rec_id"));
|
---|
32 | slika.setRedenBroj(result.getInt("reden_broj"));
|
---|
33 | slika.setPic(new String(result.getBytes("slika"), StandardCharsets.UTF_8));
|
---|
34 | sliki.add(slika);
|
---|
35 | }
|
---|
36 |
|
---|
37 | result.close();
|
---|
38 | prepStm.close();
|
---|
39 | DB.closeConnection();
|
---|
40 |
|
---|
41 | return sliki;
|
---|
42 | }
|
---|
43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.