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/SostojkiRespository.java

    r3e572eb r501396e  
    1 package com.example.cookbook.repository;public class SostojkiRespository {
     1package com.example.cookbook.repository;
     2
     3
     4import com.example.cookbook.dbConfig.DB;
     5import com.example.cookbook.model.Slika;
     6import com.example.cookbook.model.Sostojka;
     7import org.springframework.stereotype.Repository;
     8
     9import java.nio.charset.StandardCharsets;
     10import java.sql.Connection;
     11import java.sql.PreparedStatement;
     12import java.sql.ResultSet;
     13import java.sql.SQLException;
     14import java.util.ArrayList;
     15import java.util.List;
     16
     17@Repository
     18public 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    }
    249}
Note: See TracChangeset for help on using the changeset viewer.