I'm trying to compare an object from a list before inserting it into the database, but it returns the address of the object.
Follow the code.
DAO class method
public List<ServicoVO> verificaNome(ServicoVO servico) throws SQLException{
String sql = ("SELECT nome_servico FROM servico where nome_servico like '%" + servico.getNome_servico() + "%'");
List<ServicoVO> servicos = new ArrayList<ServicoVO>();
PreparedStatement stmt = con.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
while(rs.next()){
servico.setNome_servico(rs.getString("nome_servico"));
servicos.add(servico);
}
return servicos;
}
Methods of class BO
Here I compare if the name is equal to that of the list, if it is not equal insert, if it is not inserted.
public void incluirServico(ServicoVO ServicoVO) throws SQLException {
ServicoDAO dao = new ServicoDAO();
if(verificaServico(ServicoVO).equals(ServicoVO.getNome_servico())){
System.out.println("Valores iguais , item não cadastrado");
}else{
dao.incluirServico(ServicoVO);
}
}
Here it returns a list of services
public List<ServicoVO> verificaServico(ServicoVO Servico) throws SQLException {
List<ServicoVO> servico = new ServicoDAO().verificaNome(Servico);
return servico;
}
Class ServicoVO
public String getNome_servico() {
return nome_servico;
}
public void setNome_servico(String nome_servico) {
this.nome_servico = nome_servico;
}
How could I compare the result of the VerifyService method without it bringing me
the address of the object in the incluirServico
method.