title: How to show dynamic List in PDFTable in iText
body: <p>I need your help in displaying the list of earnings which is retrieved from a database in a <code>PDFTable</code> in iText. The earnings will be having two columns which are: earnings_description and earnings_amount which are defined in a separate class called Earnings. The java code for retrieving them is:</p>
  
  <pre><code>List&lt;Earnings&gt; listEarnings = new ArrayList&lt;Earnings&gt;();
  
  try{
      Connection con = Database.getConnection();
      PreparedStatement ps = con.prepareStatement("select * from Earnings");
      List&lt;Earnings&gt; listEarnings = new ArrayList&lt;Earnings&gt;();
      ResultSet rs = ps.executeQuery();
              while (rs.next()) {
                  Earnings e = new Earnings();
                  e.setEarningsDescription(rs.getString("Earning_description"));
                  e.setEarningsAmount(rs.getString("Earning_amount"));
                  listEarnings.add(e);
      }
  catch(Exception e)){
  System.out.println("Error");
  }      
  </code></pre>
  
  <p>However I tried to create a table to place the values under the headers, but I need some help. Below is the code: </p>
  
  <pre><code>PdfPTable table = new PdfPTable(2);
  Font font = new Font(FontFamily.HELVETICA, 14, Font.BOLD, BaseColor.WHITE);
  PdfPCell c1 = new PdfPCell(new Phrase("Earning Description"),font);
  c1.setHorizontalAlignment(Element.ALIGN_CENTER);
  table.addCell(c1);
  
  c1 = new PdfPCell(new Phrase("Earning Amount"),font);
  c1.setHorizontalAlignment(Element.ALIGN_CENTER);
  table.addCell(c1);
  </code></pre>
  
  <p>Now I need your assistant in adding the values under each header.</p>