0
I am trying to execute a query in my Webservice, but the function that query is inside of, break from nothing.
My code:
public boolean excluir(String usuario)
{
String sql = "DELETE * FROM listaproduto where uclogin=?";
Boolean retorno = false;
PreparedStatement pst = Conexao.getPreparedStatement(sql);
try {
pst.setString(1, usuario); //Ele quebra nessa parte.
if(pst.executeUpdate()>0)
{
retorno = true;
}
} catch (SQLException ex) {
Logger.getLogger(ProdutoDAO.class.getName()).log(Level.SEVERE, null, ex);
retorno = false;
}
return retorno;
}
Error:
GET Requestfailed Requestfailed --> Status: (500) Answer: { HTTP Status 500 - Internal Server Error
type Exception report
messageInternal Server Error
descriptionThe server encountered an Internal error that prevented it from fulfilling this request.
Exception
javax.servlet.Servletexception: java.lang.Nullpointerexception
root cause
java.lang.Nullpointerexception
note The full stack Traces of the Exception and its root causes are available in the Glassfish Server Open Source Edition 4.1.1 logs. Glassfish Server Open Source Edition 4.1.1
}
Gives error ? If yes edit the question and put the error shown
– Isac
I’ve already changed, can identify?
– Renato Crispim
What is the return of
Conexao.getPreparedStatement(sql);
? If it is null, it will fail to call the methodsetString()
– Denis Rudnei de Souza
The return is the user I type, and I debug and it comes the username I write same but it breaks.
– Renato Crispim
It seems to me that a Preparestatement is not coming, it is coming null in the call Conexao.getPreparedStatement(sql)
– Jeterson Miranda Gomes
The variable
usuario
is probably null, so the problem is not in this code snippet, but in the place that calls the delete.– Guilherme Nascimento
Post the error that appears in the glasfish LOG that we will show you the exact error.
– Filipe L. Constante