Click here to Skip to main content
15,888,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried nearly everything... Please help anyone. The output is showing as: 123456789javax.swing.ImageIcon@2f672341BUILD SUCCESSFUL (total time: 21 seconds)
But the image is not displaying.

What I have tried:

Java
public class viewimage extends javax.swing.JFrame {

    private javax.swing.JLabel img123;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField jTextField1;
    
    String path;
    int i;
     private String image;
   
    public viewimage() {
        initComponents();
    }

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
 try {
            System.out.print(1);
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sample1", "root", "");
            System.out.print(2);
            Statement st = con.createStatement();
            System.out.print(3);
            ResultSet rs = st.executeQuery("select * from images where name = '" + jTextField1.getText() + "'");
 if (rs.next()) {
                 System.out.print(4);
                    path = rs.getString("image");
                    System.out.print(5);
                    rs.absolute(i+1);
                    ImageIcon image = new ImageIcon(rs.getBytes("image"));
                    System.out.print(6);
                    Image im = image.getImage();
                    System.out.print(7);
                    Image myImg = im.getScaledInstance(img123.getWidth(),  img123.getHeight(),Image.SCALE_SMOOTH);
                    
                    System.out.print(8);
                     System.out.print(9);
                    img123.setIcon(image);
                    System.out.print(image);
                    getContentPane().add(img123);
            }
            else{
                    JOptionPane.showMessageDialog(null, "No Data");
                }
} catch (Exception e) {
            e.printStackTrace();
        }

    }
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        jTextField1.setText("");
        img123.setIcon(null);
    } 
Posted
Updated 23-Feb-17 1:40am
v3
Comments
Richard MacCutchan 23-Feb-17 5:06am    
Where is the code to set the label?
Member 13018955 23-Feb-17 7:43am    
I am sorry to say that was not the correct code. I have posted the correct code above. The previous code was a variation to see if it works. It doesn't. I have posted the correct code above.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900