我想从访问数据库中检索图像,并希望在netbeans中的jlabel上显示它。我在Google上搜索了很多但是我找不到从MS Access检索图像的代码。有人可以帮我解决这个问题吗?我编写了以下代码,但它无法正常工作。它给了我错误
未找到记录
DbConn obj = new DbConn();
String PatientID = getPid().getText();
String query = "Select [PatientEarImage] from PatientRecord where PatientID='"+PatientID+"'";
ResultSet rs= obj.Search(query);
try
{
while(rs.next())
{
byte[] img = rs.getBytes("PatientEarImage");
ImageIcon immgg;
immgg = new ImageIcon();
Image im = immgg.getImage();
Image myImg= im.getScaledInstance(getUpload().getWidth(), getUpload().getHeight(), Image.SCALE_SMOOTH);
ImageIcon newImage = new ImageIcon("PatientEarImage.jpg");
upload.setIcon(newImage);
}
}
catch (Exception ex)
{
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "No Record Found");
}
答案 0 :(得分:0)
尝试此代码。我也将MS Access数据库用作后端数据库
Blob filenameBlob = rs.getBlob("picture");
byte[] content = filenameBlob.getBytes(1L, (int) filenameBlob.length());
ImageIcon AA = new ImageIcon(content);
Image BB = AA.getImage();
Image CC = BB.getScaledInstance(FRAMEBOXPIC.getWidth(), FRAMEBOXPIC.getHeight(),
java.awt.Image.SCALE_SMOOTH);
AA = new ImageIcon(CC);
FRAMEBOXPIC.setIcon(AA);