How to convert byte array to blob

Anjali :

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
}
Pablo :
Blob blob = new javax.sql.rowset.serial.SerialBlob(bytes);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related