Error while trying to delete with DELETE method using web service Rest in Java

Asked

Viewed 310 times

1

I created a Web Service REST in Java. All operations are working except that of DELETE which returns the following error:

print do erro 405

HTTP DELETE method:

@DELETE
@Path("excluir/{idpromocao}")
public void excluir(@PathParam("idpromocao") int idpromocao){    
    Promocao P = new Promocao();
    P.setIdpromocao(idpromocao);

    PromocaoOp promo = new PromocaoOp();
    P = promo.buscar(P);

    promo.remove(P);
}

Exclusion method:

public void remove(Promocao promocao) {
    id_conexao = N.Conectar();

    String sql = "delete from promocao where idpromocao=?";

    try {


        stmt = id_conexao.prepareStatement(sql);
        stmt.setInt(1, promocao.getIdpromocao());

        //executa
        stmt.execute();

        System.out.println("Excluido");

    } catch (SQLException e) {
        System.err.println("ERRO ao excluir promoção - " + e);

    } finally {
        N.Desconectar();
    }
}
  • I believe it should be duplicated: https://answall.com/q/214147/132

  • Other similar case: https://answall.com/q/220738/132

1 answer

0

See the first line of your figure:

imagem

There it says:

GET SolicitaçãoFailed RequestFailed --> Status: (405)

Notice that the first word is GET. It should be written DELETE.

That is, the code that is trying to call your service is using the wrong HTTP method.

Also, take a look in that question to improve your JDBC code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.