【发布时间】:2012-06-07 18:22:30
【问题描述】:
我将访问者的图像和其他详细信息存储到表 tbl_visitor 中。代码如下,
String string_op="F:\\POSTERS\\Roses\\TROPIC4.png";
File imageFile = new File(string_op);
FileInputStream fis = new FileInputStream(imageFile);
String queryVis="insert into tbl_visitor(visitor_name,contact_no," +
"job_profile,org_name,photo_id_proof,type_of_visitor,date," +
"extra_people,image) values('"+
name_of_visitor.getText()+"','"+
contact_num.getText()+"','"+
job_profile.getText()+"','"+
org.getText()+"','"+
photo_id_num.getText()+"','"+
type_of_visitor.getSelectedItem().toString()+"','"+
date_and_time.getText()+"','"+
tf1.getText()+"','"+
"fis,(int)imageFile.length()"+"')";
现在我想在 JFrame 上显示图像并使用 JLabel 显示图像 但我无法将图像分配给 JLabel。我尝试了以下代码来显示图像,但它给了我错误。
Blob image_vis = rs1.getBlob(10);
image_cap.setIcon(image_vis);
请帮帮我。
【问题讨论】:
-
嗯,SetIcon方法的参数类型必须是ImageIcon类型。所以我会尝试将 Blob 转换为 ImageIcon。不是 100% 肯定这会起作用,因为我不熟悉 Blob 类。
-
单个代码行 >400 字符宽?!?您必须有一个非常宽的显示器。为了我们其他人的利益,请在 SO 引入滚动条之前强制换行。
标签: java mysql swing netbeans-7