source: src/main/java/com/example/cookbook/repository/NarackiRepository.java@ cab1b7d

Last change on this file since cab1b7d was cab1b7d, checked in by Blazho <aleksandar.blazhevski@…>, 5 months ago

Added naracki page with view of all

  • Property mode set to 100644
File size: 1.1 KB
Line 
1package com.example.cookbook.repository;
2
3
4import com.example.cookbook.dbConfig.DB;
5import com.example.cookbook.model.Naracka;
6import org.springframework.stereotype.Repository;
7
8import java.sql.Connection;
9import java.sql.ResultSet;
10import java.sql.SQLException;
11import java.sql.Statement;
12import java.time.LocalDateTime;
13import java.util.ArrayList;
14import java.util.List;
15
16@Repository
17public class NarackiRepository {
18
19
20 public List<Naracka> findAll() throws SQLException {
21
22 Connection connection = DB.getConnection();
23 Statement stm = connection.createStatement();
24 String query = "select vreme, telefon from naracki;";
25
26 ResultSet result = stm.executeQuery(query);
27 List<Naracka> naracki = new ArrayList<>();
28
29 while (result.next()){
30 Naracka naracka = new Naracka();
31 naracka.setVreme(result.getObject("vreme", LocalDateTime.class));
32 naracka.setTelefon(result.getString("telefon"));
33 naracki.add(naracka);
34 }
35
36 DB.closeConnection();
37 result.close();
38 stm.close();
39 return naracki;
40 }
41}
Note: See TracBrowser for help on using the repository browser.