title: how to make a download button to retrieve pdf file in sql database?(java swing)
body: <p>Good day everyone! I am trying to create a desktop application using java swing wherein the user can upload pdf files to the mysql database. I already did the upload part in the application, but I'm having trouble on making a download button in the application. The function of the <code>download</code> button is to retrieve the <code>pdf</code> file in the mysql database and then download it in the user's computer.</p>
  
  <p>here's what I found in inserting pdf file from <a href="https://www.java-tips.org/other-api-tips-100035/69-jdbc/845-how-to-storeretrieve-pdf-document-tofrom-sqlserver.html" rel="nofollow noreferrer">https://www.java-tips.org/other-api-tips-100035/69-jdbc/845-how-to-storeretrieve-pdf-document-tofrom-sqlserver.html</a> 
  The above link has already a function in getting pdf data, but I can't seem to understand how to implement it in my download button.</p>
  
  <pre><code>  public void upload(Connection conn,String filename) {
          int len;
          String query;
          PreparedStatement pstmt;
  
          try {
              File file = new File(filename);
              FileInputStream fis = new FileInputStream(file);
              len = (int)file.length();
              query = ("insert into fileStorage VALUES(?,?,?)");
              pstmt = conn.prepareStatement(query);
              pstmt.setString(1,file.getName());
              pstmt.setInt(2, len);
  
              //method to insert a stream of bytes
              pstmt.setBinaryStream(3, fis, len); 
              pstmt.executeUpdate();
  
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>What I'm having a trouble is making a function for my download button. how do I retrieve the file from database and download it at the same time after clicking the <code>download</code> button.</p>