I am trying to make an anti-plagiarism check on Java in my method in this way.

if (split.trim().toLowerCase().equalsIgnoreCase(antis.trim().toLowerCase())) { anti.append(antis).append(" "); } 

where the split variable is a long text from the client and the antis variable is from the base the whole problem is that when I launch my query in the facade, antis is always the last entry

code from the front

 public String getText() throws Exception{ Query query = null; String answ = null; query = em.createQuery("Select m.text from MyBd m "); List<String> strings = query.getResultList(); for (String answer: strings) { answ = answer; } return answ; } 
  • one
    And what should be? - xAqweRx
  • there is a lot of records in the database, it takes only the last one - Aslan Kussein
  • Once again I ask, what should be? - xAqweRx
  • he has to pull out all the records from the facade - Aslan Kussein
  • 2
    At each iteration of the loop, you overwrite the answer variable, and then return its value at the last iteration. - Sergey Gornostaev

1 answer 1

The facade code must be different to pull out all the entries.

 public ArrayList<String> getText() throws Exception{ Query query = null; ArrayList<String> answ = new ArrayList(); query = em.createQuery("Select m.text from MyBd m "); List<String> strings = query.getResultList(); for (String answer: strings) { answ.add( answer ) ; } return answ; } 

then the result will be an array of strings from the database. And then check too in the cycle