DragonFramework

使用Spring+Hibernate实现Oracle数据库BlOB数据

系统 2192 0

1。Spring配置

  <? xml version="1.0" encoding="ISO-8859-1" ?>
<! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >

< beans >
 
< description > Dragon Framework </ description >
 
<!--  Message source  -->
 
< bean  id ="messageSource"  class ="org.springframework.context.support.ResourceBundleMessageSource" >
  
< property  name ="basenames" >
   
< list >
    
< value > webResources </ value >
    
< value > appResources </ value >
   
</ list >
  
</ property >
 
</ bean >

 
<!--  //////////////////// Data source //////////////////////  -->
 
<!--  Oracle  -->
 
< bean  id ="dataSource"  class ="org.springframework.jndi.JndiObjectFactoryBean" >
  
< property  name ="jndiName"  value ="java:comp/env/jdbc/dragon"   />
 
</ bean >
 
<!--  
  <bean id="dataSource"
  class="org.apache.commons.dbcp.BasicDataSource"
  destroy-method="close">
  <property name="driverClassName">
  <value>oracle.jdbc.driver.OracleDriver</value>
  </property>
  <property name="url">
  <value>jdbc:oracle:thin:@172.16.184.2:1521:oradb</value>
  </property>
  <property name="username">
  <value>fushun</value>
  </property>
  <property name="password">
  <value>111111</value>
  </property>
  </bean> 
 
-->
 
<!-- Blob field hander for Oracle9i or Oracle10g -->
 
< bean  id ="nativeJdbcExtractor"  class ="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
  lazy-init
="true"   />

 
< bean  id ="lobHandler"  class ="org.springframework.jdbc.support.lob.OracleLobHandler"  lazy-init ="true" >
  
< property  name ="nativeJdbcExtractor"  ref ="nativeJdbcExtractor"   />
 
</ bean >

 
<!--  Hibernate Session Factory  -->
 
< bean  id ="sessionFactory"  class ="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
  
< property  name ="dataSource"  ref ="dataSource"   />
  
< property  name ="lobHandler"  ref ="lobHandler"   />
  
< property  name ="mappingDirectoryLocations" >
   
< list >
    
< value > classpath:/com/longtop/po </ value >
   
</ list >
  
</ property >
  
< property  name ="hibernateProperties" >
   
< props >
    
< prop  key ="hibernate.dialect" > org.hibernate.dialect.OracleDialect </ prop >
    
< prop  key ="hibernate.show_sql" > true </ prop >
    
< prop  key ="hibernate.cglib.use_reflection_optimizer" > true </ prop >
   
</ props >
  
</ property >
 
</ bean >
 
<!--  IBatis Sql Map Client Factory  -->
 
< bean  id ="sqlMapClient"  class ="org.springframework.orm.ibatis.SqlMapClientFactoryBean" >
  
< property  name ="configLocation"  value ="WEB-INF/sql-map-config.xml"   />
  
< property  name ="dataSource"  ref ="dataSource"   />
 
</ bean >
 
< bean  id ="jdbcTemplate"  class ="org.springframework.jdbc.core.JdbcTemplate" >
  
< property  name ="dataSource"  ref ="dataSource" ></ property >
 
</ bean >

 
< bean  id ="sqlMapClientTemplate"  class ="org.springframework.orm.ibatis.SqlMapClientTemplate" >
  
< property  name ="sqlMapClient"  ref ="sqlMapClient" ></ property >
 
</ bean >

 
< bean  id ="hibernateTemplate"  class ="org.springframework.orm.hibernate3.HibernateTemplate" >
  
< property  name ="sessionFactory"  ref ="sessionFactory"   />
 
</ bean >
 
<!--  Hibernate Transaction manager  -->
 
< bean  id ="hibernateTransactionManager"  class ="org.springframework.orm.hibernate3.HibernateTransactionManager" >
  
< property  name ="sessionFactory"  ref ="sessionFactory"   />
 
</ bean >

 
< bean  id ="jdbcTransactionManager"  class ="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
  
< property  name ="dataSource"  ref ="dataSource"   />
 
</ bean >
</ beans >

2。持久对象(PO)

持久对象中的BLOB对象类型为byte[]类型

3。获取页面传过来的文件

 

   SysUserPO user  =   new  SysUserPO();
  
   
// 1.获取Flower对象
   Flower flower  = (Flower)SpringHelper.getBean( " flower " );
   
// 2.解析request
   flower.parseRequest(request); 
   
// 3.获取上传的文件
   FlowerRequest flowerRequest  =  flower.getFlowerRequest();  
   ArrayList flowerFileList 
=  flower.getFlowerFileList();
   
if (flowerFileList.size() > 0 ) ... {
     
// 将数字签名文件射入user对象
      for (Iterator iter  =  flowerFileList.iterator(); iter.hasNext();)  ... {
       FlowerFile file 
=  (FlowerFile)iter.next();
       
if ( ! file.getName().equals( "" ))
       
... {
         InputStream in 
=  file.getInputStream();
         
byte [] data  =   new   byte [in.available()];
         in.read(data);
         user.setEFileContent(data);
         user.setEFileName(System.currentTimeMillis()
+ " . " + file.getPostfix());
       }

     }

   }

4。用service保存

 

     public   void  saveUser(SysUserPO user)  ... {
        hibernateTemplate.save(user);
        hibernateTemplate.flush();
    }
 

使用Spring+Hibernate实现Oracle数据库BlOB数据类型的读写


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论