title: HTTP Status 405 – Method Not Allowed on @DELETE method
body: <p>I created a webservice that accesses a MySQL database, but when I try to delete records, I always get the following return:</p>
  
  <p><strong>HTTP Status 405 - Method Not Allowed.</strong> The method received in the request-line is known by the origin server but not supported by the target resource.</p>
  
  <p>When I run the same query on the console of the database, the record is deleted. I saw several tutorials using the @DELETE method in the same way, I can not find the reason.</p>
  
  <p>This is the code for my WS:</p>
  
  <pre><code>package ws;
  
  import com.google.gson.Gson;
  import dao.PokemonDAO;
  import dao.TrainerDAO;
  import java.util.ArrayList;
  import javax.ws.rs.core.Context;
  import javax.ws.rs.core.UriInfo;
  import javax.ws.rs.Produces;
  import javax.ws.rs.Consumes;
  import javax.ws.rs.DELETE;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.PUT;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.core.MediaType;
  import model.Pokemon;
  import model.Trainer;
  
  /**
   * REST Web Service
   *
   * @author sandrini
   */
  @Path("pokews")
  public class PokedexWebService {
  
      PokemonDAO pokemonDAO = new PokemonDAO();
      TrainerDAO trainerDAO = new TrainerDAO();
  
      @Context
      private UriInfo context;
  /**
   * Creates a new instance of PokedexWebService
   */
  public PokedexWebService() {
  }
  
  /**
   * Retrieves representation of an instance of teste.GenericResource
   * @return an instance of java.lang.String
   */
  @GET
  @Produces(MediaType.APPLICATION_XML)
  public String getXml() {
      //TODO return proper representation object
      throw new UnsupportedOperationException();
  }
  
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("poke/list")
  public ArrayList&lt;Pokemon&gt; pokeList() {
      return pokemonDAO.listPokemon();
  }
  
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("poke/fetch/{id}")
  public Pokemon pokeFetch(@PathParam("id") int id) {
      return pokemonDAO.fetchPokemon(id);
  }
  
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("poke/isFavorite/{id}")
  public String pokeIsFavorite(@PathParam("id") int id) {
      return pokemonDAO.isFavorite(id);
  }
  
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("poke/{login}/{pwd}")
  public Trainer pokelogin(@PathParam("login") String login, @PathParam("pwd") String pwd) {
      return trainerDAO.authUser(login, pwd);
  }
  
  @DELETE
  @Path("poke/delete/{id}")
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  public boolean delete(@PathParam("id")int id) {
      return pokemonDAO.deletePokemon(id);
  }
  
  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Path("poke/insert")
  public boolean pokeInsert(String content) {
      Gson gson = new Gson();
      Pokemon pokemon = (Pokemon) gson.fromJson(content, Pokemon.class);
      return pokemonDAO.insertPokemon(pokemon);
  }
  
  @PUT
  @Consumes(MediaType.APPLICATION_JSON)
  @Path("poke/update")
  public boolean pokeUpdate(String content) {
      Gson gson = new Gson();
      Pokemon pokemon = (Pokemon) gson.fromJson(content, Pokemon.class);
      return pokemonDAO.updatePokemon(pokemon);
  }
  
  /**
   * PUT method for updating or creating an instance of GenericResource
   * @param content representation for the resource
   */
  @PUT
  @Consumes(MediaType.APPLICATION_XML)
  public void putXml(String content) {
  }
  
  
  }
  </code></pre>
  
  <p>This is the code for my DAO:</p>
  
  <pre><code>package dao;
  
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.util.ArrayList;
  
  import dbconn.ConnectionFactory;
  import model.Pokemon;
  
  public class PokemonDAO {
  
  
  public boolean insertPokemon(Pokemon pokemon) {
  
      try {
          Connection conn = ConnectionFactory.getConnection();
  
          String insertQuery = "INSERT INTO `pokedex`.`pokemon` (`name`,`species`,`weight`,`height`,`image`,`isFavorite`,`trainerId`) "
                              + "VALUES (?, ?, ?, ?, ?, 0, ?)";
  
          PreparedStatement stmt = conn.prepareStatement(insertQuery);
          stmt.setString(1, pokemon.getName());
          stmt.setString(2, pokemon.getSpecies());
          stmt.setString(3, pokemon.getWeight());
          stmt.setString(4, pokemon.getHeight());
          stmt.setString(5, pokemon.getImage());
                      stmt.setInt(6, pokemon.getTrainerId());
  
          stmt.executeUpdate();
                      stmt.close();
          conn.close();
  
      } catch (Exception e) {
          e.printStackTrace();
          return false;
      }
  
      return true;
  
  }
  
  public boolean deletePokemon(int id) {      
  
      try {
          Connection conn = ConnectionFactory.getConnection();
  
          String deleteQuery = "DELETE FROM `pokedex`.`pokemon` WHERE id = ?;";
  
          PreparedStatement stmt = conn.prepareStatement(deleteQuery);
          stmt.setInt(1
                              , id);
  
          stmt.executeUpdate();
                      stmt.close();
          conn.close();
  
      } catch (Exception e) {
          e.printStackTrace();
          return false;
      }
  
      return true;    
  }
  
  
  public ArrayList&lt;Pokemon&gt; listPokemon() {
      ArrayList&lt;Pokemon&gt; pokemonList = new ArrayList&lt;Pokemon&gt;();
  
      try {
          Connection conn = ConnectionFactory.getConnection();
  
          //String listQuery = "SELECT * fROM `pokedex`.`pokemon`";
          String listQuery = "SELECT `pokemon`.`id`,\n" +
                                          "    `pokemon`.`name`,\n" +
                                          "    `pokemon`.`species`,\n" +
                                          "    `pokemon`.`weight`,\n" +
  "    `pokemon`.`height`,\n" +
  "    `pokemon`.`image`,\n" +
  "    `pokemon`.`isFavorite`,\n" +
  "    `pokemon`.`trainerId`\n" +
  "FROM `pokedex`.`pokemon`;";
  
          PreparedStatement stmt = conn.prepareStatement(listQuery);
          ResultSet rs = stmt.executeQuery();
  
          while(rs.next()) {
              Pokemon pokemon = new Pokemon();
  
              pokemon.setId(rs.getInt(1));
              pokemon.setName(rs.getString(2));
              pokemon.setSpecies(rs.getString(3));
              pokemon.setWeight(rs.getString(4));
              pokemon.setHeight(rs.getString(5));
              pokemon.setImage(rs.getString(6));
              pokemon.setIsFavorite(rs.getString(7));
              pokemon.setTrainerId(rs.getInt(8));
  
              pokemonList.add(pokemon);
          }
  
          rs.close();
                      stmt.close();
          conn.close();
  
      } catch (Exception e) {
          e.printStackTrace();
          return null;
      }
  
      return pokemonList;
  }
  
  public Pokemon fetchPokemon(int id) {
      Pokemon pokemon = null;
  
      try {
          Connection conn = ConnectionFactory.getConnection();
  
  
          String fetchQuery = "SELECT * fROM `pokedex`.`pokemon` WHERE id = ?;";
  
          PreparedStatement stmt = conn.prepareStatement(fetchQuery);
          stmt.setInt(1, id);
  
          ResultSet rs = stmt.executeQuery();
  
          if(rs.next()) {
              pokemon = new Pokemon();
              pokemon.setId(rs.getInt(1));
              pokemon.setName(rs.getString(2));
              pokemon.setSpecies(rs.getString(3));
              pokemon.setWeight(rs.getString(4));
              pokemon.setHeight(rs.getString(5));
              pokemon.setImage(rs.getString(6));
              pokemon.setIsFavorite(rs.getString(7));
              pokemon.setTrainerId(rs.getInt(8));
          } else {
              return pokemon;
          }
  
          rs.close();
                      stmt.close();
          conn.close();
  
      } catch (Exception e) {
          e.printStackTrace();
          return null;
      }
  
      return pokemon;
  }
  
  public boolean updatePokemon(Pokemon pokemon) {
  
      try {
          Connection conn = ConnectionFactory.getConnection();
  
          String insertQuery = "UPDATE `pokedex`.`pokemon` SET `name` = ?, `species` = ?, `weight` = ?, "
                              + "`height` = ?, `image` = ?, `isFavorite` = ? WHERE `id` = ?;";
  
  
  
          PreparedStatement stmt = conn.prepareStatement(insertQuery);
          stmt.setString(1, pokemon.getName());
          stmt.setString(2, pokemon.getSpecies());
          stmt.setString(3, pokemon.getWeight());
          stmt.setString(4, pokemon.getHeight());
          stmt.setString(5, pokemon.getImage());
                      stmt.setString(5, pokemon.isFavorite());
          stmt.setInt(6, pokemon.getId());
  
          stmt.executeUpdate();
                      stmt.close();
          conn.close();
  
      } catch (Exception e) {
          e.printStackTrace();
          return false;
      }
  
      return true;
  }
  
      public String isFavorite(int id) {
      Pokemon pokemon = null;
  
      try {
          Connection conn = ConnectionFactory.getConnection();
  
  
          String fetchQuery = "SELECT teste fROM `pokedex`.`pokemon` WHERE id = ?;";
  
          PreparedStatement stmt = conn.prepareStatement(fetchQuery);
          stmt.setInt(1, id);
  
          ResultSet rs = stmt.executeQuery();
  
          if(rs.next()) {
              pokemon = new Pokemon();
              pokemon.setIsFavorite(rs.getString(1));
          } else {
              return pokemon.isFavorite();
          }
  
          rs.close();
                      stmt.close();
          conn.close();
  
      } catch (Exception e) {
          e.printStackTrace();
          return pokemon.isFavorite();
      }
  
      return pokemon.isFavorite();
  }
  }
  </code></pre>
  
  <p>I didn't make a code to request it. I'm running my tests on Netbeans, using the "Test Restful Web Services" tool. Could it be the reason of the problem?</p>
  
  <p>This is the tool where I run my tests on Netbeans:
  <a href="https://i.stack.imgur.com/VCkvy.png" rel="nofollow noreferrer">"Test Restful Web Services" tool</a></p>