private void DownloadFormButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DownloadFormButtonActionPerformed
    //Get selected value and split it to get the first integer
    // which is the ID of the form
    String ID = (String) FormsList.getSelectedValue();
    String[] test = ID.split(" ");
    Integer formID = Integer.parseInt(test[0]);
    
    DatabaseConnection db = new DatabaseConnection();
    Connection conn = db.connectToDB();

    InputStream inStream = null;
    String title = "";
    String sql = "Select * From `HDForms` where ID = '"+formID+"'";
    ResultSet rs = db.getResults(conn, sql);

        
        try {
            if (rs.next())
            {
                inStream = rs.getBinaryStream("Content");
                title = rs.getString("Title");
            }
        } catch (SQLException ex) {
            Logger.getLogger(AllForms.class.getName()).log(Level.SEVERE, null, ex);
        }
    
        OutputStream outStream;
        try {
            int read = 0;
            byte[] bytes = new byte[1024];
            String curDir = System.getProperty("user.dir");
            outStream = new FileOutputStream(new File(title+".pdf"));
            try {
                while ((read = inStream.read(bytes)) != -1)
                {
                    outStream.write(bytes, 0, read);
                }
            } catch (IOException ex) {
                Logger.getLogger(AllForms.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                inStream.close();
                outStream.flush();
                outStream.close();
                JOptionPane.showMessageDialog(frame,
                    "File downloaded to: " + curDir);
            } catch (IOException ex) {
                Logger.getLogger(AllForms.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(AllForms.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_DownloadFormButtonActionPerformed