import java.sql.SQLException; import java.sql.Statement; import java.sql.Connection; import java.sql.ResultSet; import java.sql.DriverManager; import java.util.ArrayList; class Program01 { public static ArrayList getEmployees() { ArrayList employeeList = new ArrayList<>(); Connection conn = null; try { String url = "jdbc:mysql://localhost:3306/surubt"; conn = DriverManager.getConnection(url, "surubt", "titok"); String sql = "select * from employees"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); while(rs.next()) { Employee emp = new Employee( rs.getInt("id"), rs.getString("name"), rs.getString("city"), rs.getDouble("salary"), rs.getDate("birth").toLocalDate() ); employeeList.add(emp); } }catch(SQLException ex) { System.err.println("Hiba! Az SQL művelet sikertelen!"); System.err.println(ex.getMessage()); } return employeeList; } public static void main(String[] args) { ArrayList employeeList; employeeList = getEmployees(); employeeList.forEach(emp -> { System.out.println(emp.name); }); } }