public Address getByID(int id) { Address address = null; int addressId = 0, typeId = 0; String addressValue = EOF, typeValue = EOF; try { _commandString = "SELECT * FROM " + ADDRESS_TABLE + " WHERE " + ID + " = " + id + ""; _resultSet = _statement.executeQuery(_commandString); while (_resultSet.next()) { addressId = _resultSet.getInt(ID); addressValue = _resultSet.getString(ADDRESS); typeId = _resultSet.getInt(ADDRESSTYPE_ID); typeValue = _dao.typeGateway().getById(ADDRESS_TABLE, typeId); address = new Address(Address.AddressType.valueOf(typeValue), addressValue, id); address.setID(addressId); } _resultSet.close(); } catch (Exception e) { _dao.processSQLError(e); } return address; }
public Collection<Address> getAll() { Address address = null; ArrayList<Address> addresses = new ArrayList<Address>(); int addressId = 0, typeId = 0, clientId = 0; String addressValue = EOF, typeValue = EOF; try { _commandString = "SELECT * FROM " + ADDRESS_TABLE + ""; _resultSet = _statement.executeQuery(_commandString); } catch (Exception e) { _dao.processSQLError(e); } try { while (_resultSet.next()) { addressId = _resultSet.getInt(ID); clientId = _resultSet.getInt(CLIENT_ID); addressValue = _resultSet.getString(ADDRESS); typeId = _resultSet.getInt(ADDRESSTYPE_ID); typeValue = _dao.typeGateway().getById(ADDRESS_TABLE, typeId); address = new Address(Address.AddressType.valueOf(typeValue), addressValue, clientId); address.setID(addressId); addresses.add(address); } _resultSet.close(); } catch (Exception e) { _dao.processSQLError(e); } return addresses; }