public void insert(Funcionario funcionario) { Connection conexao = new Conexao().getConexao(); try { PreparedStatement preparedStatement = conexao.prepareStatement( "INSERT INTO funcionarios(nome, sobrenome, telefone, endereco_id, salario, email, cpf, nascimento, senha, gerente) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); preparedStatement.setString(1, funcionario.getNome()); preparedStatement.setString(2, funcionario.getSobrenome()); preparedStatement.setString(3, funcionario.getTelefone()); preparedStatement.setInt(4, funcionario.getEndereco().getId()); preparedStatement.setDouble(5, funcionario.getSalario()); preparedStatement.setString(6, funcionario.getEmail()); preparedStatement.setString(7, funcionario.getCpf()); preparedStatement.setDate(8, funcionario.getNascimento()); preparedStatement.setString(9, funcionario.getSenha()); preparedStatement.setBoolean(10, funcionario.isGerente()); preparedStatement.executeUpdate(); conexao.close(); } catch (SQLException ex) { Logger.getLogger(FuncionarioDAO.class.getName()).log(Level.SEVERE, null, ex); } }
public void update(Funcionario funcionario) { Connection conexao = new Conexao().getConexao(); try { PreparedStatement preparedStatement = conexao.prepareStatement( "UPDATE funcionarios SET nome=?, sobrenome=?, telefone=?, endereco_id=?, salario=?, email=?, cpf=?, nascimento=?, edited=now(), senha=?, gerente=? WHERE id = ?;"); preparedStatement.setString(1, funcionario.getNome()); preparedStatement.setString(2, funcionario.getSobrenome()); preparedStatement.setString(3, funcionario.getTelefone()); preparedStatement.setInt(4, funcionario.getEndereco().getId()); preparedStatement.setDouble(5, funcionario.getSalario()); preparedStatement.setString(6, funcionario.getEmail()); preparedStatement.setString(7, funcionario.getCpf()); preparedStatement.setDate(8, funcionario.getNascimento()); preparedStatement.setString(9, funcionario.getSenha()); preparedStatement.setBoolean(10, funcionario.isGerente()); preparedStatement.setInt(11, funcionario.getId()); preparedStatement.executeUpdate(); conexao.close(); } catch (SQLException ex) { Logger.getLogger(FuncionarioDAO.class.getName()).log(Level.SEVERE, null, ex); } }