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