1
I am trying to remove a data from the bank, but the following error happens:
Parameter index out of range (1 > number of Parameters, which is 0)
Can you help me?
public void remove(Bean e) {
try {
PreparedStatement stmt = ConexaoMysql.getConexao()
.prepareStatement("DELETE FROM coluna WHERE id = 5");
stmt.setInt(1,e.getId());
stmt.execute();
stmt.close();
System.out.println("Removido!");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public class TesteRemover {
public static void main(String[] args) {
Bean p = new Bean ();
Dao dao = new Dao ();
p.setIdexemplo(5);
dao.remove(p);
}
}
But still my die is not removed
– João souza
@Joãosouza try to force the id value (integer) to be removed from preparedStatement for example stmt.setInt(1,5); It seems to me that your e.getId(); does not refer to the same attribute of p.setIdexemplo(5); but to be sure of this you would need to add the source of the Bean class;
– Reginaldo Soares
I realized that Voce changed the initial SQL of the question I will change the answer to maintain coherence.
– Reginaldo Soares
"Forcing" the dice is removed but I wanted to remove by my main.
– João souza
try to replace stmt.setInt(1,e. getId()); for something like stmt.setInt(1,e. getIdexemplo());
– Reginaldo Soares
Nothingness............
– João souza
add the source of your question Bean Class
– Reginaldo Soares
private int id; private String name; private float number; private Calendar data;
– João souza
This is my bean
– João souza
Joao Oce needs to add the font to the question completely so I can analyze and help you, what is probably happening is that you are not setting the same attribute that you are giving get.
– Reginaldo Soares
the problem was in the bean, already solved thank you :)
– João souza