public static Contact trouverClient(DAOFactory daoFactory, long id) throws SQLException { String SQL_SELECT_PAR_ID = "SELECT * FROM contact_tb WHERE id = ?"; Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; Contact client = null; try { connection = daoFactory.getConnection(); preparedStatement = initialisationRequetePreparee(connection, SQL_SELECT_PAR_ID, false, id); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { client = new Contact(); client.setId(resultSet.getLong("id")); client.setNom(resultSet.getString("nom")); client.setPrenom(resultSet.getString("prenom")); client.getDonnees().setEmail(resultSet.getString("email")); client.getDonnees().setTel(resultSet.getString("tel")); client.getDonnees().setPays(resultSet.getString("pays")); client.getDonnees().setVille(resultSet.getString("ville")); client.getDonnees().setAdresse(resultSet.getString("adresse")); } } catch (SQLException e) { throw new DAOException(e); } finally { fermeturesSilencieuses(resultSet, preparedStatement, connection); } return client; }
/* * Simple méthode utilitaire permettant de faire la correspondance(le * mapping) entre une ligne issue de la table des places assises du restaurant (un * ResultSet) et un bean Table. */ public static Contact mapContact(ResultSet resultSet) throws SQLException { Contact contact = new Contact(); contact.setId(resultSet.getLong("id")); contact.setNom(resultSet.getString("nom")); contact.setPrenom(resultSet.getString("prenom")); contact.getDonnees().setEmail(resultSet.getString("email")); contact.getDonnees().setTel(resultSet.getString("tel")); contact.getDonnees().setPays(resultSet.getString("pays")); contact.getDonnees().setVille(resultSet.getString("ville")); contact.getDonnees().setAdresse(resultSet.getString("adresse")); return contact; }