Reputation: 914
i am trying to build a simple webservice with the usual CRUD methods connected to a database. So far i managed to list all the "clients" from my table through the URL (receive a JSON string), but im not being able to remove or retrieve a row by passing a "id" parameter and i dont know why because i dont receive any error.
My work has 5 classes:
Cliente.java
The class variables with SET,GET, hashCode and equal methods.
ClienteResource.java
@GET
@Path("/remove/{id}")
@Produces("text/plain")
public String removeId(@PathParam ("id") int id) {
return new Controller().removerCliente(id);
}
Controller.java
public String removerCliente (int id) {
return ClienteDAO.getInstance().removerCliente(id);
}
ClienteDAO.java
public class ClienteDAO extends ConnectionFactory {
...
public String removerCliente (int id) {
Connection conexao = null;
PreparedStatement psmt = null;
ResultSet rs = null;
conexao = criarConexao();
String query = "Delete * from cliente where id = ?";
try {
psmt = conexao.prepareStatement(query);
psmt.setInt(1, id);
psmt.execute();
} catch (Exception e) {
} //finally {
//fecharConexao(conexao, psmt, rs);
//}
return "O clientecom o id:"+ id +" foi apagado com sucesso!";
}
}
}
Can you identify something wrong? Thank you!
Upvotes: 0
Views: 1485
Reputation: 1555
Dont use * in your query:
String query = "Delete from cliente where id = ?";
Upvotes: 1
Reputation: 80
Delete * from cliente where id = ? Are you sure this query is correct?
Upvotes: 0