1、首先数据表中的clob类型对应java持久化类的String类型;而blob类型对应byte[]类型
2、定义hibernate标签时,持久化类中对应clob类型的属性的hibernate type为
org.springframework.orm.hibernate.support.ClobStringType ;
而对应blob类型的属性的hibernate type应为
org.springframework.orm.hibernate.support.BlobByteArrayType。
在 VO 的 hbm.xml 里面的配置
在Spring 配置文件( applicationContext.xml ) 的配置
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
<bean id="nativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor" />
<!-- 用于配置 oracle clob -->
<bean id ="oracleLobHandle" class ="org.springframework.jdbc.support.lob.OracleLobHandler" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
destroy-method="close">
.........
..........
<!-- 用于配置 clob -->
<property name ="lobHandler" >
<ref bean ="oracleLobHandle" />
</property>
</bean>
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
插入操作
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
String url = "jdbc:oracle:thin:@192.168.0.115:1521:rck";
String userName = "scott";
String password = "tiger";
Connection conn =
DriverManager.getConnection (url, userName, password);
String policyInfo="....."; //假设这个变量很大
for(int i=0;i<800;i++)
{
policyInfo+="美舍雅阁成为家庭化妆台的主力品牌,我们是中国市场的第二个宝洁jj262361。";
}
/* 设定不自动提交 */
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
try {
/* 插入一个空的CLOB对象 */
Statement stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO coinfo VALUES ('111', EMPTY_CLOB(),'liuj')");
/* 查询此CLOB对象并锁定 */
ResultSet rs = stmt.executeQuery("SELECT c_context FROM coinfo WHERE c_id='111' FOR UPDATE");
while (rs.next()) {
/* 取出此CLOB对象 */
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("c_context");
/* 向CLOB对象中写入数据 */
BufferedWriter outt = new BufferedWriter(clob.getCharacterOutputStream());
StringReader in = new StringReader(policyInfo);
int c;
while ((c=in.read())!=-1) {
outt.write(c);
}
outt.flush();
in.close();
outt.close();
System.out.println("成功~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
conn.commit();
} catch (Exception ex) {
/* 出错回滚 */
conn.rollback();
throw ex;
}
/* 恢复原提交状态 */
conn.setAutoCommit(defaultCommit);