title: Result set from database to itextpdf
body: <p>I'm new in java and I use itextpdf as my output. <br>
  Right now I am so flustered by this problem. <br><br></p>
  
  <p>My problem is that I want to display the resultset from the database in pdf format with a twist.<br><br>
  for example, i will set a table with 3 columns,<br>
  and these are the resultset from the database,<br><br></p>
  
  <p>Name<br>
  John<br>
  Jane<br>
  Mary<br>
  Sonny<br>
  Kiel<br><br></p>
  
  <p>so now the output in itextpdf should be viewed like this</p>
  
  <p>|__ columnname _|__ columnname_|_columnname__|<br>
  |_____John______|_____Jane_____|_____Mary____|<br>
  |_____Sonny_____|_____Kiel_____|_____________|<br></p>
  
  <p><br>
  I want the results to be inserted in every column and i don't have any idea how to do this.<br><br></p>
  
  <p>anyone? it would be nice if someone can guide me. <br><br></p>
  
  <pre><code>Document document = new Document(PageSize.A4, 25, 25, 25, 25);
  PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream("D:\\PURCHASEORDER\\"+see+".pdf"));
  document.open();
  try {
      Class.forName(driver);
      conn = DriverManager.getConnection(url+db, user, pass);
      Statement st = conn.createStatement();
      String zero = dates.getSelectedItem().toString();
      String sql = "select name as hehe from names where  servedate = '"+zero+"'";
      pst=conn.prepareStatement(sql);
      rs=pst.executeQuery();
  
      Rectangle react = writer.getPageSize();
      PdfPTable table2 = new PdfPTable(new float[] { 3,3,3});
      table2.setTotalWidth(527);
      table2.getDefaultCell().setBorder(Rectangle.NO_BORDER);
      PdfPCell cell = new PdfPCell(new Paragraph(""));
      cell.setColspan(8);
      cell.setHorizontalAlignment(Element.ALIGN_LEFT);
      cell.setBackgroundColor(BaseColor.GRAY);
      table2.addCell(cell);
      table2.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
  
      while(rs.next()){
          String v1 = rs.getString("hehe");
          FontFactory.getFont(FontFactory.TIMES_BOLD,14,BaseColor.BLACK)));
          table2.addCell(new Paragraph("TOTAL Number: "+v1+"", FontFactory.getFont(FontFactory.TIMES_ROMAN,12,BaseColor.BLACK)));
          table2.addCell(new Paragraph("TOTAL Number: "+v1+"", FontFactory.getFont(FontFactory.TIMES_ROMAN,12,BaseColor.BLACK)));
          table2.addCell(new Paragraph("TOTAL Number: "+v1+"", FontFactory.getFont(FontFactory.TIMES_ROMAN,12,BaseColor.BLACK)));
  
      }
      table2.setWidthPercentage(100);
      document.add(table2);
  
  } catch (Exception e) {
      JOptionPane.showMessageDialog(null, e);
  }
  document.close();
  String pdfFile="D:\\PURCHASEORDER\\"+see+".pdf";
  File f = new File(pdfFile);
  if (pdfFile.toString().endsWith(".pdf")) {
      Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + pdfFile);
  } else {
      //For cross platform use
      Desktop desktop = Desktop.getDesktop();
  
      desktop.open(f);
  }
  </code></pre>