public ArrayList<Person> ReadAll() throws SQLException
{
statement = connection.createStatement();
ArrayList<Person> list = new ArrayList<Person>();
ArrayList<Phone> phones;
Person person;
query="SELECT * FROM PERSONS;";
result = statement.executeQuery(query);
while ( result.next() )
{
person = new Person();
person.setId(result.getInt("ID"));
person.setFistname(result.getNString("FISTNAME"));
person.setSurname(result.getNString("SURNAME"));
person.setAge(result.getInt("AGE"));
phones = new ArrayList<Phone>();
query="SELECT * FROM PHONES WHERE PERSONID="+person.getId()+";";
Statement statementPhone = connection.createStatement();
ResultSet resultPhone = statementPhone.executeQuery(query);
while (resultPhone.next())
{
Phone phone = new Phone();
phone.setPhone(resultPhone.getNString("PHONE"));
phones.add(phone);
}
resultPhone.close();
person.setPhone(phones);
list.add(person);
}
statement.close();
return list;
}