0
I am creating a function to insert new users in the database, but present this error: "incompatible types: Boolean cannot be converted to Usuarios". Does anyone know a way to solve this case:
public String InsertUserCpf(@PathParam("nome")String nome,
@QueryParam("email") String email,
@QueryParam("senha") String senha,
@QueryParam("dtnasc") Date dtnasc,
@QueryParam("fone") String fone,
@QueryParam("oab") String oab,
@QueryParam("cep") String cep,
@QueryParam("cpf") String cpf)
{
Usuarios u = new Usuarios();
u.setNome(nome);
u.setEmail(email);
u.setSenha(senha);
u.setDtnasc(dtnasc);
u.setFone(fone);
u.setOab(oab);
u.setCep(cep);
u.setCpf(cpf);
UsuarioDAO dao = new UsuarioDAO();
u = dao.inserir(u);
Gson g = new Gson();
return g.toJson(u);
}
Usuariodao.java:
public boolean inserir(Usuarios usuario)
{
String sql = "INSERT INTO usuarios(nome,email,senha,dtnasc,fone,oab,cep,cpf) VALUES(?,?,?,?,?,?,?,?)";
Boolean retorno = false;
PreparedStatement pst = Conexao.getPreparedStatement(sql);
try {
pst.setString(1, usuario.getNome());
pst.setString(2, usuario.getEmail());
pst.setString(3, usuario.getSenha());
pst.setDate(4, usuario.getDtnasc());
pst.setString(5, usuario.getFone());
pst.setString(6, usuario.getOab());
pst.setString(7, usuario.getCep());
pst.setString(8, usuario.getCpf());
if(pst.executeUpdate()>0)
{
retorno = true;
}
} catch (SQLException ex) {
Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex);
retorno = false;
}
return retorno;
}
Where does the error occur? Which line?
– user28595
this command which shows the error: u = dao.insert(u);
– Kathe Quandt
Return
boolean
to signal whether error or not is a bad programming practice. This hides errors, their causes and makes it difficult to recover. It was precisely so that programmers would not do this, that the exceptions were invented, so use them.– Victor Stafusa
From what you’re saying, it seems to be the case mark an answer as accepted. Here we do not write "solved" in the question. If you have an answer that really helped you, mark it as accepted. If you came to the solution on your own, put in the solution as an answer. So content is more organized and easier to find in the future by other people with similar problems
– Denis Rudnei de Souza