首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

Hibernate在SqlServer中下传图像

2012-09-22 
Hibernate在SqlServer中上传图像1、sqlServer中photo表字段(int id,image image,varchar contentType)2、htm

Hibernate在SqlServer中上传图像

1、sqlServer中photo表字段(int id,image image,varchar contentType)

2、html页面如下:

?3、uploadPhotoAction如下:

Integer photoId;try {   FileInputStream in = new FileInputStream(photo);   byte[] b = new byte[in.available()];   in.read(b);   in.close();   Photo image = new Photo();   image.setContentType(uploadContentType);   image.setImage(Hibernate.createBlob(b));   Session  session = sessionFactory.getCurrentSession();   session.save(image);} catch (FileNotFoundException e) {e.printStackTrace();return "error";} catch (IOException e) {e.printStackTrace();return "error";}catch (RuntimeException re) {re.printStackTrace();throw re;}return "success";}

?

?

热点排行