title: How to store a pdf file in postgresql database using servlets?
body: <p>I am uploading a file from HTML <br></p>
  
  <pre><code> &lt;center&gt;&lt;form action="pdf" method="post" enctype="multipart/form-data"&gt;
         &lt;b&gt;Upload Certificate&lt;/b&gt;
         &lt;input type="file" name="file"/&gt;&lt;/center&gt;
        &lt;center&gt; &lt;input type="submit" /&gt;&lt;/center&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>On submitting the form, pdf Servlet is called. Inside the servlet the request object is parsed and file(pdf) is read using InputStream as given in code below.</p>
  
  <pre><code>protected void doPost(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
      throws ServletException, IOException
    {
      try
      {
        List localList = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(paramHttpServletRequest);
        for (FileItem localFileItem : localList)
        {
          String str1 = localFileItem.getFieldName();
          String str2 = FilenameUtils.getName(localFileItem.getName());
          System.out.println("fieldname:" + str1);
          System.out.println("filename:" + str2);
          InputStream localInputStream = localFileItem.getInputStream();
          try
          {
            PdfReader localPdfReader = new PdfReader(localInputStream);
            paramHttpServletResponse.sendRedirect("takedetails.jsp");
          }
          catch (InvalidPdfException localInvalidPdfException)
          {
            paramHttpServletResponse.sendRedirect("upload.jsp");
          }
  
        }
  
      }
      catch (FileUploadException localFileUploadException)
      {
        throw new ServletException("Cannot parse multipart request.", localFileUploadException);
      }
    }
  </code></pre>
  
  <p>As you can see,I used InputStream object to check for file format as pdf. <br><br>
  <strong>Now I want to save this pdf file to postgresql Database. What field should i use in postgresql and how can I get the file from InputStream object to store it in database?</strong></p>