public static List<AtividadeComercial> getListOfAtividadeComercial() { List<AtividadeComercial> lista = new ArrayList<AtividadeComercial>(); Connection connection = ConnectionFactory.getConnection("mydb", "root", "root"); String sql = "select * from AtividadeComercial"; ResultSet rs = null; PreparedStatement stmt = null; try { stmt = connection.prepareStatement(sql); rs = stmt.executeQuery(); while (rs.next()) { AtividadeComercial atividade = new AtividadeComercial(); atividade.setIdAtividadeComercial(rs.getInt("idAtividadeComercial")); atividade.setNomeAtividade(rs.getString("nomeAtividade")); lista.add(atividade); } rs.close(); stmt.close(); return lista; } catch (SQLException ex) { Logger.getLogger(AtividadeComercialDAO.class.getName()).log(Level.SEVERE, null, ex); return null; } }