コード例 #1
0
  @Override
  public Client findClient(Integer codeClient) throws DAOException {
    Connection connection;
    Client client = new Client();

    try {
      connection = JDBCUtil.getConnection();
      PreparedStatement prepareStatement =
          connection.prepareStatement("SELECT * FROM Client c WHERE c.codecl=?");
      prepareStatement.setInt(1, codeClient);
      ResultSet resultSet = prepareStatement.executeQuery();
      resultSet.next();

      client.setCodeClient(resultSet.getInt("codecl"));
      client.setNomClient(resultSet.getString("nomcl"));
      client.setAdresse(resultSet.getString("adresse"));
      client.setVille(resultSet.getString("ville"));

    } catch (InstantiationException
        | IllegalAccessException
        | ClassNotFoundException
        | SQLException e) {
      throw new DAOException(e.getMessage(), e.getCause());
    }
    return client;
  }
コード例 #2
0
  @Override
  public List<Client> findAllByName() throws DAOException {
    Connection connection;
    List<Client> clients = new ArrayList<>();

    try {
      connection = JDBCUtil.getConnection();
      PreparedStatement prepareStatement =
          connection.prepareStatement("SELECT * FROM Client c ORDER BY c.nomcl");
      ResultSet resultSet = prepareStatement.executeQuery();

      while (resultSet.next()) {
        Client client = new Client();
        client.setCodeClient(resultSet.getInt("codecl"));
        client.setNomClient(resultSet.getString("nomcl"));
        client.setAdresse(resultSet.getString("adresse"));
        client.setVille(resultSet.getString("ville"));
        clients.add(client);
      }
    } catch (InstantiationException
        | IllegalAccessException
        | ClassNotFoundException
        | SQLException e) {
      throw new DAOException(e.getMessage(), e.getCause());
    }
    return clients;
  }