Ignore:
Timestamp:
02/03/24 15:58:58 (9 months ago)
Author:
Blazho <aleksandar.blazhevski@…>
Branches:
master
Children:
aea04dd
Parents:
3e572eb
Message:

added missing files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/cookbook/repository/SlikiZaReceptRepository.java

    r3e572eb r501396e  
    1 package com.example.cookbook.repository;public class SlikiZaReceptRepository {
     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    }
    243}
Note: See TracChangeset for help on using the changeset viewer.