public int insert(ClienteDTO dto) { String sql = "INSERT INTO CLIENTE VALUES (?,?,?,?,?)"; PreparedStatement stmt = null; try { stmt = con.prepareStatement(sql); stmt.setDouble(1, dto.getClienteCpf()); stmt.setString(2, dto.getNome()); stmt.setString(3, dto.geteMail()); // ver o date com o prof de sexta se está correto stmt.setDate(4, new java.sql.Date(dto.getDataDeNascimento().getTime())); stmt.setString(5, dto.getTelefone()); return stmt.executeUpdate(); } catch (SQLException ex) { ex.printStackTrace(); } return 0; }
public int update(ClienteDTO dto) { String sql = "UPDATE CLIENTE " + "SET CLIENTE_CPF = ?, " + "SET NOME = ?, " + "SET E_MAIL = ?, " + "SET DT_NASCIMENTO = ?, " + "SET TELEFONE = ?, " + "WHERE CLIENTE_CPF = ?"; PreparedStatement stmt = null; try { stmt = con.prepareStatement(sql); stmt.setDouble(1, dto.getClienteCpf()); stmt.setString(2, dto.getNome()); stmt.setString(3, dto.geteMail()); // ver o date com o prof de sexta se está correto stmt.setDate(4, new java.sql.Date(dto.getDataDeNascimento().getTime())); stmt.setString(5, dto.getTelefone()); stmt.setDouble(6, dto.getClienteCpf()); return stmt.executeUpdate(); } catch (SQLException ex) { ex.printStackTrace(); } return 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; }
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; }