空間站

          北極心空

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            15 Posts :: 393 Stories :: 160 Comments :: 0 Trackbacks
          /*
               * 將對象轉化成java.sql.Blob 
               * 要求 對象是序列化的
               
          */
              
          public  java.sql.Blob ObjectToBlob(Object obj)  throws  IOException{
                  
          try  {
                      ByteArrayOutputStream out 
          =   new  ByteArrayOutputStream();
                      ObjectOutputStream outputStream 
          =   new  ObjectOutputStream(out);
                      outputStream.writeObject(obj);
                      
          byte [] bytes  =  out.toByteArray();
                      outputStream.close();
                      
          return  Hibernate.createBlob(bytes);
                  } 
          catch  (Exception e) {
                      
          //  TODO: handle exception
                      System.out.println( " ObjectToBlob " );
                      
          return   null ;
                  }        
              }
              
              
              
          /*
               * 將java.sql.Blob 轉化成 對象 相應對象
               * 要求 對象是序列化的
               
          */     
              
          public  Object BlobToObject(java.sql.Blob desblob,Object obj)  throws  IOException{
                  
          try  {
                      ObjectInputStream in 
          =   new  ObjectInputStream(desblob.getBinaryStream());
                      obj 
          =   in.readObject();
                      in.close();    
                      
          return  obj;
                  } 
          catch  (Exception e) {
                      
          //  TODO: handle exception
                      System.out.println( " BlobToObject " );
                      e.printStackTrace();
                      
          return   null ;
                  }        
              }    
              
          posted on 2008-08-01 12:46 蘆葦 閱讀(869) 評論(0)  編輯  收藏 所屬分類: 數據庫JAVAHibernate
          主站蜘蛛池模板: 武清区| 进贤县| 德格县| 湟源县| 天水市| 喀喇| 江北区| 顺平县| 翁牛特旗| 景宁| 常宁市| 潮安县| 政和县| 伊川县| 东辽县| 唐河县| 遵义县| 梁平县| 宜阳县| 三明市| 隆尧县| 宁陕县| 遵义县| 舒城县| 本溪市| 海淀区| 筠连县| 衡山县| 巍山| 泸定县| 永春县| 元阳县| 阿拉善右旗| 右玉县| 海口市| 镇坪县| 大同县| 宜阳县| 建始县| 平昌县| 申扎县|