17

I want to fetch an image from database. For that I have created a byte array for an image, which is passed by a string, and now I want to convert that string into image format. I am assigning that image to a Jlabel field. The code is as follows:

try {
    Blob image_vis = rs1.getBlob(10);
    InputStream x=image_vis.getBinaryStream();
    OutputStream out=new FileOutputStream(string_op);
    byte[] bytes = string_op.getBytes();
    String s=new String(bytes);
    System.out.println(+s);  //prints bytes for the string
    ImageIcon icon_cap = new ImageIcon(string_op);
    image_cap.setIcon(icon_cap);   //prints nothing to Jlabel
    //image_cap.setText(s);     //prints a path of a image
}
Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
Anjali
  • 269
  • 2
  • 6
  • 13

1 Answers1

38
Blob blob = new javax.sql.rowset.serial.SerialBlob(bytes);
Pablo
  • 3,655
  • 2
  • 30
  • 44