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 | |
---|
1 | package com.example.cookbook.repository;
|
---|
2 |
|
---|
3 |
|
---|
4 | import com.example.cookbook.dbConfig.DB;
|
---|
5 | import com.example.cookbook.model.Naracka;
|
---|
6 | import org.springframework.stereotype.Repository;
|
---|
7 |
|
---|
8 | import java.sql.Connection;
|
---|
9 | import java.sql.ResultSet;
|
---|
10 | import java.sql.SQLException;
|
---|
11 | import java.sql.Statement;
|
---|
12 | import java.time.LocalDateTime;
|
---|
13 | import java.util.ArrayList;
|
---|
14 | import java.util.List;
|
---|
15 |
|
---|
16 | @Repository
|
---|
17 | public 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.