title: Select multiple files shown on JTable and download them from the MySQL database
body: <p>I have written code for <code>JButton</code> to download selected files represented on a <code>JTable</code> from the MySQL database. I want it to download all selected files.Initially i was able to download one file at a time.now i have edited the code and it does nothing and returns no error. what could be wrong in the code.</p>
  
  <p>How can I achieve this in my code?  </p>
  
  <p>My code:</p>
  
  <pre><code>private void jButtonDownloadActionPerformed(java.awt.event.ActionEvent evt) {
  
      int BUFFER_SIZE = 4096;
  
      try {
           int[] selected_rows= jTable1.getSelectedRows();
           for (int i = 0; i &lt; selected_rows.length;  i++){
               if (i &lt; selected_rows.length - 1 ) {
          String tableClick=(jTable1.getModel().getValueAt(selected_rows[i],i).toString());
      Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee_certificate","root","");
          String sql= "SELECT Cert, Cert_Name FROM certificate WHERE Cert_Code =?" ;
          PreparedStatement pstmt =  con.prepareStatement(sql);
          pstmt.setString(1, tableClick);
          ResultSet rs=pstmt.executeQuery();
          if(rs.next()){
              String filename = rs.getString("Cert_Name");
              Blob blob = rs.getBlob("Cert");
              InputStream inputStream = blob.getBinaryStream();
              String filePath ="C:\\Users\\User\\Downloads\\Documents\\"+filename;
              OutputStream outputStream = new FileOutputStream(filePath);
  
              int bytesRead = -1;
              byte[] buffer = new byte[BUFFER_SIZE];
              while ((bytesRead = inputStream.read(buffer)) != -1) {
                  outputStream.write(buffer, 0, bytesRead);
              }
  
              inputStream.close();
              outputStream.close();
              JOptionPane.showMessageDialog(null,"file saved to Documents in your C folder.");
          }}} }
          catch (Exception e)
          {JOptionPane.showMessageDialog(null,e);}}
  </code></pre>