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