title: "Query-loop" to get the appropriate value out of the DB
body: <p>So I will have to explain what I'm looking for and I will use an example very general to this so this could help others with the same problem:</p>
  
  <p>Lets assume I'm working at the police station and I'm creating a DB with a table called "Policestations" and the Police of my country has 3 policestations.</p>
  
  <p>Those stations wan't to be as efficient as possible therefore they will pick those incidents if they fullfill some parameters for our example here those 3 policestations:</p>
  
  <ul>
  <li><p>policeStation:1010</p>
  
  <ul>
  <li>offender:GuyA</li>
  <li>place:GB (iso-code)</li>
  <li>delict:murder</li>
  </ul></li>
  <li><p>policeStation:2020</p>
  
  <ul>
  <li>offender:GuyA</li>
  <li>place: *  (* = "for not relevant")</li>
  <li>delict:murder</li>
  </ul></li>
  <li><p>policeStation:3030</p>
  
  <ul>
  <li>offender:GuyB</li>
  <li>place:*</li>
  <li>delict:*</li>
  </ul></li>
  </ul>
  
  <p>So now, I have a method that looks like that (could someone edit this the <code>code thing</code> doesnt work when I add that into it):</p>
  
  <pre><code>public String responsiblePoliceStation(String offender, String place, String delict) {
      Query q = em.createQuery("SELECT a.Policestation FROM PoliceStations a WHERE a.offender = :offender AND a.place = :place AND a.delict = :delict );
      q.setParameter("offender", offender);
      q.setParameter("place", place);
      q.setParameter("delict", delict);
  
      String policestation = (String) q.getSingleResult();
  
      return policestation;
  }
  </code></pre>
  
  <p>so now I can call that method for example with that:</p>
  
  <pre><code>PSPRouteService psp = new PSPRouteService();
  String pS = psp.responsiblePoliceStation("GuyA", "GB", "murder");
  </code></pre>
  
  <p>`</p>
  
  <p>and this will work fine, I will get as response that the policeStation with String 1010 has to "solve" this incident.... but as I intended in the header I want a loop so for example thats assume I have that incident:</p>
  
  <ul>
  <li>offender: GuyA</li>
  <li>place: Brazil</li>
  <li>delict: murder</li>
  </ul>
  
  <p>then this wouldnt work because I dont know how to implement that, if some parameter doesn't fit in then just compare it with the next row and look if the next Policestation is more tolerant and doesn't care for example whether the incident took place.</p>
  
  <p>So I want kinda a query-loop where I compare the given Parameter with my DB and if something doesnt fit I just skip to the next row compare that and if that doesnt fit I keep going to the next and as you see above the third policeStation is more tolerant they dont care, what happend and where they just take the incident if the offender was GuyB...... so any ideas and tipps how to implement that?</p>