import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import org.mariadb.jdbc.Connection; import org.mariadb.jdbc.Statement; public class DataService { DataSource dataSource; public DataService(DataSource dataSurce) { this.dataSource = dataSurce; } public ArrayList getEmployees() { ArrayList empList = null; try { empList = tryGetEmployees(); } catch (SQLException e) { System.err.println("Hiba! A lekérdezés sikertelen!"); System.err.println(e.getMessage()); } return empList; } public ArrayList tryGetEmployees() throws SQLException { ArrayList empList = new ArrayList<>(); Connection conn = this.dataSource.connect(); String sql = "select * from Employees"; Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sql); while(rs.next()) { Employee emp = new Employee(); emp.id = rs.getInt("id"); emp.name = rs.getString("name"); emp.city = rs.getString("city"); emp.salary = rs.getDouble("salary"); empList.add(emp); } return empList; } }