Spring + Hibernate 存取Blob和Clob
[b] 1.Spring配置[/b] OracleLobHandler定义 [b]Oracle 9i按如下定义[/b] [b]Oracle 10g及以上或其他数据库按如下定义[/b] [b]2.持久化对象定义[/b] private byte[] blobcontent;//Blob private String clobcontent; //Clob [b]3.Hibernate映射文件hbm.xml配置[/b] Blob对应的Spring数据类型为org.springframework.orm.hibernate3.support.BlobByteArrayType Clob对应的Spring数据类型为org.springframework.orm.hibernate3.support.ClobStringType [b]4.Java操作类[/b] //写Lob对象 FileInputStream fis = new FileInputStream("F:\\bear\\test.jpg"); byte[] data = new byte[(int) fis.available()]; fis.read(data); fis.close(); UserInfo po = new UserInfo(); po.setBlobcontent(data); po.setClobcontent("222222222222222"); //读Lob对象 byte[] b = po.getBlobcontent(); OutputStream fos=null; try { fos = new FileOutputStream("D:\\test10.jpg"); fos.write(b); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }