public String saveBlobImage(Person person,String imagePath) throws IOException{
String userName=null;
System.out.println("执行到这类了");
InputStream in=this.getClass().getResourceAsStream(imagePath);
System.out.println("这里执行了吗");
System.out.println("是空的吗?"+in.available());
byte[] buffer=new byte[in.available()];
in.read(buffer);
in.close();
person.setImage(Hibernate.createBlob(buffer));
tr=session.beginTransaction();
session.save(person);
tr.commit();
userName=person.getUserName();
return userName;
}
public void getBlobImage(String userName,String targetPath) throws SQLException, IOException{
tr=session.beginTransaction();
Person person=(Person)session.load(Person.class, new String(userName));
Blob image=person.getImage();
InputStream in=image.getBinaryStream();
OutputStream out=new FileOutputStream(targetPath);
int count;
while((count=in.read())!=-1){
out.write(count);
}
out.close();
in.close();
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载