Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ArrayList<Persona> findPersona(String cognome, String nome) throws SQLException {
- String apice = "'";
- Persona pers = null;
- Statement s = con.createStatement();
- ResultSet rs = null;
- String query = "select Id, Username, Cognome, Nome, Citta, Pwd, Data_di_Nascita from utenti_demo Where ";
- ArrayList<Persona> persone = new ArrayList<>();
- try {
- if (cognome.contains(apice) || nome.contains(apice)) {
- return null;
- }
- if (!cognome.isEmpty() && !nome.isEmpty()) {
- rs = s.executeQuery(query + "Nome Like'" + nome + "%" + "' && Cognome Like'" + cognome + "%" + "'");
- }
- else if (nome.isEmpty()) {
- rs = s.executeQuery(query + "Cognome Like'" + cognome + "%" + "'");
- }
- else if (cognome.isEmpty()) {
- rs = s.executeQuery(query + "nome Like '" + nome + "%" + "'");
- }
- while (rs.next()) {
- /*pers = new Persona(rs.getInt(1),rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5),
- rs.getString(6), rs.getDate(7));*/
- persone.add(pers);
- }
- } finally {
- if (rs != null) {
- rs.close();
- }
- }
- return persone;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement