读书人

Hibernate在SqlServer中下传图像

发布时间: 2012-09-22 21:54:54 作者: rapoo

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";}

?

?

读书人网 >图形图像

热点推荐