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 App { public static ArrayList getEmployees() { ArrayList employeeList = new ArrayList<>(); Connection conn = null; try { Class.forName("org.mariadb.jdbc.Driver"); String url = "jdbc:mariadb://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()); }catch(ClassNotFoundException ex) { System.err.println("Hiba! A MariaDB driver nem található!"); 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); }); } }