- Timestamp:
- 02/03/24 15:58:58 (9 months ago)
- Branches:
- master
- Children:
- aea04dd
- Parents:
- 3e572eb
- 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 { 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 } 2 43 }
Note:
See TracChangeset
for help on using the changeset viewer.