Credo che dovrebbe andar bene in questo modo![]()
codice:public static ArrayList<Persona> getDati() { try { String driver = "com.mysql.jdbc.Driver"; Class.forName(driver); String url = "jdbc:mysql://localhost:3306/progetto"; Connection con = DriverManager.getConnection(url, "root", ""); Statement cmd = con.createStatement(); String qry = "SELECT * FROM persona"; ArrayList<Persona> lista = new ArrayList<Persona>(); ResultSet res = cmd.executeQuery(qry); while (res.next()) lista.add(new Persona(res.getString("idPersona"), res.getString("nome"), res.getString("cognome"), res.getString("indirizzo"), res.getString("ruolo") )); con.close(); } catch (SQLException SQLexc) { SQLexc.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return lista; }


Rispondi quotando