Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. public ArrayList<Persona> findPersona(String cognome, String nome) throws SQLException {
  2. String apice = "'";
  3.  
  4. Persona pers = null;
  5. Statement s = con.createStatement();
  6. ResultSet rs = null;
  7. String query = "select Id, Username, Cognome, Nome, Citta, Pwd, Data_di_Nascita from utenti_demo Where ";
  8. ArrayList<Persona> persone = new ArrayList<>();
  9. try {
  10. if (cognome.contains(apice) || nome.contains(apice)) {
  11. return null;
  12. }
  13. if (!cognome.isEmpty() && !nome.isEmpty()) {
  14. rs = s.executeQuery(query + "Nome Like'" + nome + "%" + "' && Cognome Like'" + cognome + "%" + "'");
  15. }
  16. else if (nome.isEmpty()) {
  17. rs = s.executeQuery(query + "Cognome Like'" + cognome + "%" + "'");
  18. }
  19. else if (cognome.isEmpty()) {
  20. rs = s.executeQuery(query + "nome Like '" + nome + "%" + "'");
  21. }
  22.  
  23. while (rs.next()) {
  24. /*pers = new Persona(rs.getInt(1),rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5),
  25. rs.getString(6), rs.getDate(7));*/
  26. persone.add(pers);
  27. }
  28. } finally {
  29. if (rs != null) {
  30. rs.close();
  31. }
  32. }
  33.  
  34. return persone;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement