-1
I’m testing the put by Postman but is giving null Pointer Exception when I try to perform @put
    @PUT
    @Path("/{idCliente}")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response atualizarCliente(@PathParam("idCliente") int id, Cliente cliente) throws Exception {
        Cliente atualizarCliente = clienteDao.encontrarPorId(cliente.getIdCliente());
        System.out.println(cliente.toString());
        atualizarCliente.setIdCliente(cliente.getIdCliente());
        atualizarCliente.setNome(cliente.getNome());
        atualizarCliente.setCpf(cliente.getCpf());
        atualizarCliente.setEmail(cliente.getEmail());
        atualizarCliente.setDataDeNascimento(cliente.getDataDeNascimento());
        clienteDao.atualizar(atualizarCliente);
        return Response.ok().build();
    }
public boolean atualizar(Cliente cliente) throws Exception {
        boolean sucessoUpdate = false;
        String sql = " UPDATE CLIENTE SET NOME = ? , CPF = ? , EMAIL = ? , DATA_NASCIMENTO = ? WHERE IDCLIENTE = "
                + cliente.getIdCliente();
        Connection conexao = Banco.getConnection();
        PreparedStatement prepStmt = Banco.getPreparedStatement(conexao, sql);
        try {
            Date data = new SimpleDateFormat("yyyy-MM-dd").parse(cliente.getDataDeNascimento());
            prepStmt.setString(1, cliente.getNome());
            prepStmt.setString(2, cliente.getCpf());
            prepStmt.setString(3, cliente.getEmail());
            prepStmt.setDate(4, new java.sql.Date(data.getTime()));
            int codigoRetorno = prepStmt.executeUpdate(sql);
            if (codigoRetorno == 1) {
                sucessoUpdate = true;
            }
        } catch (SQLException e) {
            System.out.println("Erro ao atualizar Cliente. Causa: " + e.getMessage());
        } finally {
            Banco.closePreparedStatement(prepStmt);
            Banco.closeConnection(conexao);
        }
        return sucessoUpdate;
    }
    public Cliente encontrarPorId(int id) {
        Cliente cliente = new Cliente();
        Connection conn = Banco.getConnection();
        Statement stmt = Banco.getStatement(conn);
        ResultSet rs = null;
        String query = "SELECT * FROM CLIENTE WHERE IDCLIENTE = " + id;
        try {
            rs = stmt.executeQuery(query);
            if (rs.next()) {
                cliente.setIdCliente(rs.getInt(1));
                cliente.setNome(rs.getString(2));
                cliente.setCpf(rs.getString(3));
                cliente.setEmail(rs.getString(4));
                cliente.setDataDeNascimento(rs.getString(5));
            }
        } catch (SQLException e) {
            System.out.println(
                    "Erro ao executar a Query que verifica existência de Cliente por ID. Erro:" + e.getMessage());
        } finally {
            Banco.closeResultSet(rs);
            Banco.closeStatement(stmt);
            Banco.closeConnection(conn);
        }
        return cliente;
    }
and I’m putting the url http://localhost:8080/api/clients/1 with the json body
  {
    "IDCLIENTE": 1,
    "NOME": "Alice",
    "CPF": "11111111112",
    "EMAIL": "[email protected]",
    "DATADENASCIMENTO": "1998-03-31"
    }
Add the Requestbody before the client but error appears when I try to put the Requestparam, is not giving the option to import it
– Lais Sant'ana
@Laissant'ana leaves
@PathParam("idCliente")to see if it solves :)– Lucas Bittencourt
Stopped giving null Pointer, but it is not changing the client. Postman is returning 200 but when I get this id nothing has been modified
– Lais Sant'ana