如何将字节数组转换为 blob [英] How to convert byte array to blob
本文介绍了如何将字节数组转换为 blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从数据库中获取图像.为此,我为图像创建了一个字节数组,该数组通过字符串传递,现在我想将该字符串转换为图像格式.我正在将该图像分配给 Jlabel 字段.代码如下:
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
}
推荐答案
Blob blob = new javax.sql.rowset.serial.SerialBlob(bytes);
这篇关于如何将字节数组转换为 blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文