设为首页 加入收藏

TOP

hibernate对大数据资源的处理操作(三)
2014-11-24 07:31:01 来源: 作者: 【 】 浏览:17
Tags:hibernate 对大 数据 资源 处理 操作
try { // 创建文件的输入流,将文件加载到流中 FileInputStream fis = new FileInputStream(file); // 创建blob大数据对象|||||在4之后要用这样的方式获取 Blob blob = Hibernate.getLobCreator(HiberUtil.openSession()) .createBlob(fis, file.length()); //将大数据存储到 image.setImage(blob); imageService.saveObject(image); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Test public void getImage() throws SQLException { Image image = (Image) imageService.getObject(Image.class, 1); // 判断得到得数据是否为空 if (image != null) { InputStream is = image.getImage().getBinaryStream(); File file = new File("D:\\a.jpg"); try { FileOutputStream fos = new FileOutputStream(file); byte buffer[] = new byte[1024]; int len = 0; while ((len = is.read(buffer)) != -1) { fos.write(buffer, 0, len); } fos.close(); is.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Mongo服务器集群配置学习一――主.. 下一篇不能将值NULL插入列'id'..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·一篇说人话的文章, (2025-12-27 07:50:09)
·Python Web框架哪家 (2025-12-27 07:50:06)
·基于Python的数据分 (2025-12-27 07:50:03)
·深入理解 Java 集合 (2025-12-27 07:22:48)
·Java集合框架全面解 (2025-12-27 07:22:45)