I am having a problem displaying an image retrieved from a database in a JFrame. Here is what I will use .........
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/studio","root","");
Statement st=con.createStatement();
ResultSet rs = st.executeQuery( "select image from photo_instn where cust_id='2'") ;
while(rs.next())
{
byte[] imagedata = rs.getBytes("image") ;
Image img = Toolkit.getDefaultToolkit().createImage(imagedata);
ImageIcon icon =new ImageIcon(img);
JLabel lPhoto = new JLabel(icon) ;
setLayout(null);
System.out.println("Inside");
System.out.println(lPhoto);
this.add(lPhoto) ;
lPhoto.setBounds(200,20,300,400);
}
}
This code has no problems. but the image does not appear in the frame ... Please help me solve this problem ....
source
share