8
데이터베이스에서 이미지를 가져 오려고합니다. 이를 위해 문자열로 전달 된 이미지의 바이트 배열을 만들었으므로이 문자열을 이미지 형식으로 변환하려고합니다. 그 이미지를 Jlabel 필드에 할당하려고합니다. 다음과 같이 코드는 다음과 같습니다바이트 배열을 blob로 변환하는 방법
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
}
http://stackoverflow.com/questions/6662813/easiest-way-to-convert-byte-array-into-blob-in-java –