posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          ???? /*
          ?????*?將對(duì)象轉(zhuǎn)化成java.sql.Blob?
          ?????*?要求?對(duì)象是序列化的
          ?????
          */
          ????
          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?轉(zhuǎn)化成?對(duì)象?相應(yīng)對(duì)象
          ?????*?要求?對(duì)象是序列化的
          ?????
          */ ????
          ????
          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 ;
          ????????}????????
          ????}????
          ????
          ????



          評(píng)論

          # re: 序列化和反序列化對(duì)象到 數(shù)據(jù)庫  回復(fù)  更多評(píng)論   

          2007-11-29 19:06 by 專注java開源
          收藏~

          # re: 序列化和反序列化對(duì)象到 數(shù)據(jù)庫  回復(fù)  更多評(píng)論   

          2014-11-09 18:24 by erwqe
          qwe
          主站蜘蛛池模板: 格尔木市| 关岭| 曲沃县| 新竹县| 津市市| 酒泉市| 沁阳市| 桐乡市| 伊宁市| 平遥县| 张家口市| 龙岩市| 阳朔县| 秦安县| 平谷区| 阳高县| 邮箱| 凤翔县| 来凤县| 潜山县| 建昌县| 保德县| 连江县| 嵊泗县| 济宁市| 阜阳市| 皮山县| 老河口市| 讷河市| 堆龙德庆县| 盐池县| 洛宁县| 故城县| 灵山县| 前郭尔| 静乐县| 辽阳市| 阳朔县| 宁明县| 兴宁市| 深州市|