title: How to display an image in a label after retrieveing it from JavaDB database?
body: <p>The below code is supposed to retrieve an image from the database and display it within a jlabel. After lots of trying i cannot get the image to show.  In the code below I first conenct to the JavaDB which is a simple table with only one record containing an image. I then retrieve that record and store it within the existingCustomer object. I then decode the byte array and set the array to an ImageIcon and then set the icon to a label. The problem i am having is that the output is confirming that the byte array has been stored in the icon but it will not show in the label. please help</p>
  
  <pre><code> private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  
      try {
          Customer existingCustomer = new Customer();
          String dbURL = "jdbc:derby://localhost:1527/CustDB";
          String uname = "mydb";
          String upass = "mydb";
  
  
              //Get a connection
              Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
              Connection conn = DriverManager.getConnection(dbURL, uname, upass); 
              System.out.println("Connection OK"); 
              Statement stmt = conn.createStatement();
              ResultSet results = stmt.executeQuery(
              "select photo from APP.CUSTOMER where CUSTOMER_ID = 2");
  
              while(results.next())
              {
                  existingCustomer.setPhoto(results.getBytes(1));                    
              }
              results.close();
              stmt.close();
  
              byte[] imageData = Base64.base64Decode(existingCustomer.getPhoto());
  
          System.out.println(imageData);
  
  
          if(imageData !=  null)
           {System.out.println("yes");}else{System.out.println("no");}
             ImageIcon icon = new ImageIcon(imageData);
             //BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData));
          if(icon != null){System.out.println("yes");}else{System.out.println("no");}
  
             jLabelImage.setText(null);
             jLabelImage.setIcon(icon);
  
      } catch (SQLException ex) {
          Logger.getLogger(custform.class.getName()).log(Level.SEVERE, null, ex);
      } catch (InstantiationException ex) {
          Logger.getLogger(custform.class.getName()).log(Level.SEVERE, null, ex);
      } catch (IllegalAccessException ex) {
          Logger.getLogger(custform.class.getName()).log(Level.SEVERE, null, ex);
      } catch (ClassNotFoundException ex) {
          Logger.getLogger(custform.class.getName()).log(Level.SEVERE, null, ex);
      }
  </code></pre>