昨天做项目,要网oracle10g中存贮blob数据,发现,c3p0不支持,百度了半天,结合自己探索,解决了,下面贴出解决方法
spring 配置文件配置
<!-- 开发环境数据源配置-->
<bean id="or_dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="jdbcUrl" value="jdbc:oracle:thin:@10.16.0.104:1521:orcl"></property>
<property name="user" value="ahictest"></property>
<property name="password" value="ahictest"></property>
<property name="maxPoolSize" value="20"></property>
<property name="minPoolSize" value="2"></property>
<property name="acquireIncrement" value="2"></property>
</bean>
<!-- spring处理Blob字段 -->
<bean id="lobHandler" lazy-init="true"
class="org.springframework.jdbc.support.lob.OracleLobHandler">
<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor" />
</bean>
<!-- c3p0 的配置 : -->
<bean id="nativeJdbcExtractor" lazy-init="true"
class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor" />
<bean id="or_SessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref local="or_dataSource"/>
</property>
<property name="lobHandler" ref="lobHandler" />
<property name="mappingDirectoryLocations">
java实现类代码:
jdbcTemplate.execute(sql,new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
@Override
protected void setValues(PreparedStatement pst, LobCreator lobCreator)
throws SQLException, DataAccessException {
pst.setString(1, attachment_name);
lobCreator.setBlobAsBinaryStream(pst,2,fis,(int)file.length());
pst.setString(3, attachment_name);
pst.setInt(4, attachment_size);
pst.setString(5, object_type);
pst.setString(6, pk_object);
}
});