空間站

          北極心空

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            15 Posts :: 393 Stories :: 160 Comments :: 0 Trackbacks

          公告

          本博客主要是在本人收集網上一些精彩技術文章,有時可能因疏忽轉載的時候沒有說明轉載出處和作者,如果您認為哪篇文章侵犯了你的版權,請通知本人: EMAIL:luwei-80@163.com 歡迎您光臨本博客!

          常用鏈接

          留言簿(15)

          我參與的團隊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          /*
               * 將對象轉化成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 蘆葦 閱讀(871) 評論(0)  編輯  收藏 所屬分類: 數據庫JAVAHibernate
          主站蜘蛛池模板: 合作市| 扶绥县| 新余市| 抚州市| 玉山县| 正镶白旗| 金昌市| 巴马| 百色市| 扎赉特旗| 遂川县| 石景山区| 伊川县| 礼泉县| 额济纳旗| 苏州市| 嵊泗县| 南安市| 连平县| 仙居县| 五河县| 乌拉特中旗| 惠州市| 桐庐县| 吴忠市| 湖南省| 新竹县| 利津县| 河东区| 沂南县| 麦盖提县| 凭祥市| 阿克苏市| 兴安县| 青海省| 赤峰市| 余干县| 雷州市| 德昌县| 金塔县| 永年县|