title: How to show uploaded and saved photo from database to a JLabel
body: <p>I am making a system where the user can save a picture and database. It is already saving, but I want that saved photo to be displayed on a JLabel when I click it from the JTable. I don't know the code on how make it appear, and I want it to be automatically resized according to the size of my JLabel.</p>
  
  <p>Here is the code for the Table Mouse Clicked Event:</p>
  
  <pre><code>private void tblTableMouseClicked(java.awt.event.MouseEvent evt) {                                      
          int row = tblTable.getSelectedRow();
          String selection = tblTable.getModel().getValueAt(row, 0).toString();
          String sql = "select * from LibrarySystemDatabase where No = " + selection;
          try {
              pst = conn.prepareStatement(sql);
              rs = pst.executeQuery();
              if (rs.next()) {
                  txtNo.setText(rs.getString("No"));
                  txtTitle.setText(rs.getString("Title"));
                  txtAuthor.setText(rs.getString("Author"));
                  txtGenre.setText(rs.getString("Genre"));
                  txtLexile.setText(rs.getString("Lexile"));
                  txtPoints.setText(rs.getString("Points"));
  
  
              }
          } catch (Exception e) {
              JOptionPane.showMessageDialog(null, e);
          } finally {
              try {
                  rs.close();
                  pst.close();
              } catch (Exception e) {
              }
          }
      }                            
  </code></pre>
  
  <p>Here is the code for the Upload Button:</p>
  
  <pre><code>private void btnUploadActionPerformed(java.awt.event.ActionEvent evt) {                                          
  
  
          JFileChooser chooser = new JFileChooser();
          chooser.showOpenDialog(null);
          File f = chooser.getSelectedFile();
          filename = f.getAbsolutePath();
  
          ImageIcon imageIcon =  new ImageIcon (new ImageIcon(filename).getImage().getScaledInstance(lblImage.getWidth(), lblImage.getHeight(), Image.SCALE_DEFAULT));
          lblImage.setIcon(imageIcon);
  
  
  
          try {
  
  
              File image = new File(filename);
              FileInputStream fix = new FileInputStream(image);
              ByteArrayOutputStream bos = new ByteArrayOutputStream();
              byte[] buf = new byte[1024];
              for (int number; (number = fix.read(buf)) != -1;) {
                  bos.write(buf, 0, number);
              }
              bookImage = bos.toByteArray();
          } catch (Exception e) {
              JOptionPane.showMessageDialog(null, e);
          }
  //*/
      }  
  </code></pre>
  
  <pre><code>    byte[] bookImage = null;
      String filename = null;
      private ImageIcon format = null;
  </code></pre>
  
  <p>Thanks!            </p>