I am creating a function to insert new users into the database, but I have this error: "Incompatible types: boolean can not be converted to Users". 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);
}
UserDao.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;
}