title: How to save generated PDF files to MySQL database using Java?
body: <p>I have a Java class which is generating PDF file using <a href="https://itextpdf.com/en" rel="nofollow noreferrer">iText</a> library. Now as per my need I have to save this generated PDF file to MySQL database table but I have no idea how to do it.</p>
  
  <p>My concerns are:</p>
  
  <ol>
  <li>what <em>datatype</em> should I use in MySQL column of PDF table to save PDF
  file</li>
  <li>which query will insert generated PDF file to database</li>
  </ol>
  
  <p>At present I am generating PDF file and storing it into hard-coded file path of my local disk.</p>
  
  <p>Here is my PDF generation code in Java:</p>
  
  <pre><code>OutputStream file = new FileOutputStream(new File("D://timer.pdf"));
  Document document = new Document();
  PdfWriter.getInstance(document, file);
  
  //Inserting Table in PDF
  PdfPTable table = new PdfPTable(3);
  
  PdfPCell cell = new PdfPCell(new Paragraph("Java4s.com"));
  
  cell.setColspan(3);
  cell.setHorizontalAlignment(Element.ALIGN_CENTER);
  cell.setPadding(10.0f);
  cell.setBackgroundColor(new BaseColor(140, 221, 8));
  
  table.addCell(cell);
  
  table.addCell("Name");
  table.addCell("Address");
  table.addCell("Country");
  table.addCell("Java4s");
  table.addCell("NC");
  table.addCell("United States");
  table.setSpacingBefore(30.0f);  // Space Before table starts, like margin-top in CSS
  table.setSpacingAfter(30.0f);   // Space After table starts, like margin-Bottom in CSS
  
  //Inserting List in PDF
  List list = new List(true, 30);
  list.add(new ListItem("Java4s"));
  list.add(new ListItem("Php4s"));
  list.add(new ListItem("Some Thing..."));
  
  //Text formating in PDF
  Chunk chunk = new Chunk("Welecome To Java4s Programming Blog...");
  chunk.setUnderline(+1f, -2f);//1st co-ordinate is for line width,2nd is space between
  Chunk chunk1 = new Chunk("Php4s.com");
  chunk1.setUnderline(+4f, -8f);
  chunk1.setBackground(new BaseColor(17, 46, 193));
  
  //Now Insert Every Thing Into PDF Document
  document.open();//PDF document opened........                  
  document.add(Chunk.NEWLINE);   //Something like in HTML :-)
  document.add(new Paragraph("Dear Java4s.com"));
  document.add(new Paragraph("Document Generated On - " + newDate().toString()));
  document.add(table);
  document.add(list);            //In the new page we are going to add list
  document.close();
  
  file.close();
  
  System.out.println("Pdf created successfully..");
  </code></pre>
  
  <p><br>
  Please help me.<br>
  Thanks in advance.</p>