在ole字段用长二进制数的形式保存图片,读取的时候还原为图片并保存本地(和class文件在同一目录的temp文件夹中,相对路径"temp\\temp.jpg")。Access里有两条记录,当查询一条记录完毕后,查询另一条记录,发现显示的图片是上一条记录的图片。图片是"画"上一个JPanel上的,用了paintComponent方法,如下:
- Java code
public class StudentPicture extends JPanel{ File imageFile; Toolkit tool; public StudentPicture(){ tool=getToolkit(); } public void setImage(File imageFile){ this.imageFile=imageFile; repaint(); } public void paintComponent(Graphics g){ super.paintComponent(g); int w=getBounds().width; int h=getBounds().height; if(imageFile!=null){ Image image=tool.getImage(imageFile.getAbsolutePath()); g.drawImage(image,0,0,w,h,this); } else g.drawString("没有选择照片图像",20,30); } }
odbc自行设置,数据库名是StudentInfo
------解决方案--------------------
如果第二条记录读取出来了 那就是paintComponent里是要被刷新