How to convert byte array to blob

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


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Blob blob = new javax.sql.rowset.serial.SerialBlob(bytes);

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x