LexarG56

Generation

generate functionWed, 19 Jul 2023

Como crear un metodo para consultar en una tabla de una base de datos

public List<Employees> getEmployees() { final String query = "select * from employees"; List<Employees> employees = new ArrayList<>(); try (Connection connection = getConnection(); PreparedStatement stmt = connection.prepareStatement(query); ResultSet rs = stmt.executeQuery();) { while (rs.next()) { Employee employee = new Employee(rs.getString("name"), rs.getString("lastname")); employees.add(employee); } } catch (SQLException ex) { System.err.println(ex.getMessage()); } return employees; }

Questions about programming?Chat with your personal AI assistant