Spring + Hibernate 存取Blob和Clob
1.Spring配置
OracleLobHandler定义
Oracle 9i按如下定义
<bean id="nativeJdbcExtractor"
/>
<bean id="lobHandler"
ref="nativeJdbcExtractor" />
</bean>
Oracle 10g及以上或其他数据库按如下定义
<bean id="lobHandler"
type="org.springframework.orm.hibernate3.support.BlobByteArrayType">
<column name="BLOBCONTENT" />
</property>
<property name="clobcontent" type="org.springframework.orm.hibernate3.support.ClobStringType">
<column name="CLOBCONTENT" />
</property>
4.Java操作类
//写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();
}