3
I’m trying to delete data from a table with Java but for some reason the code is not working. Excerpt from the code below:
public void excluir(ModeloObjeto modelo) throws Exception{
Connection conexao = CriaConexao.getConexao();
PreparedStatement ps;
ps = conexao.prepareCall("DELETE FROM `funcionalidade_celular` WHERE `nome_cel` LIKE ?");
ps.setString(1, "'"+modelo.getModelo()+"'");
executar(ps);
}
All other features are normal using the same logic, but only the delete one is not working. I have already printed the result of modelo.getModelo()
and did the test with the output result in the workbench and worked perfectly, but at the time of deleting by the web page it does not exclude.
Method executar
:
public void executar(PreparedStatement ps) throws Exception{
if(ps == null){
throw new NullPointerException();
}
try {
ps.execute();
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
finally{
ps.close();
}
}
Method getConexao()
:
public static Connection getConexao(){
if(conexao == null){
try {
Class.forName("com.mysql.jdbc.Driver");
conexao = DriverManager.getConnection(URL,USER,PASS);
} catch (SQLException | ClassNotFoundException ex) {
Logger.getLogger(CriaConexao.class.getName()).log(Level.SEVERE, null, ex);
}
}
return conexao;
}
Bruno, copy here the code of the execute method and getConexao. It can be some detail in these methods, such as setAutoCommit.
– Joel Lobo
Ready, I edited and put the two methods,
– Bruno Tchaikovsky
Hello Bruno, while executing your rule out is displayed something on console?
– RXSD