Example #1
0
 public ArrayList<ClienteDTO> select() {
   ArrayList<ClienteDTO> itens = new ArrayList<ClienteDTO>();
   String sql = "SELECT * FROM CLIENTE";
   Statement stmt = null;
   ResultSet rs = null;
   try {
     stmt = con.createStatement();
     rs = stmt.executeQuery(sql);
     while (rs.next()) {
       ClienteDTO dto = new ClienteDTO();
       dto.setClienteCpf(rs.getDouble(1));
       dto.setNome(rs.getString(2));
       dto.seteMail(rs.getString(3));
       // pegando a data do banco em formato date e convertendo o formato date para calendar
       dto.setDataDeNascimento(rs.getDate(4));
       dto.setTelefone(rs.getString(5));
       itens.add(dto);
     }
   } catch (SQLException ex) {
     ex.printStackTrace();
   }
   return itens;
 }
Example #2
0
 public ClienteDTO locate(int atendenteCpf) {
   String sql = "SELECT * FROM CLIENTE WHERE CLIENTE_CPF = ?";
   PreparedStatement stmt = null;
   ResultSet rs = null;
   try {
     stmt = con.prepareStatement(sql);
     stmt.setInt(1, atendenteCpf);
     rs = stmt.executeQuery();
     if (rs.next()) {
       ClienteDTO dto = new ClienteDTO();
       dto.setClienteCpf(rs.getDouble(1));
       dto.setNome(rs.getString(2));
       dto.seteMail(rs.getString(3));
       // pegando a data do banco em formato date e convertendo o formato date banco para date java
       dto.setDataDeNascimento(rs.getDate(4));
       dto.setTelefone(rs.getString(5));
       return dto;
     }
   } catch (SQLException ex) {
     ex.printStackTrace();
   }
   return null;
 }