posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(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ù)庫(kù)  回復(fù)  更多評(píng)論   

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

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

          2014-11-09 18:24 by erwqe
          qwe
          主站蜘蛛池模板: 沂水县| 新化县| 西贡区| 阳原县| 屯昌县| 于都县| 农安县| 上林县| 镇康县| 泽库县| 长武县| 吴川市| 淮安市| 交口县| 叙永县| 安溪县| 富平县| 满城县| 青川县| 清河县| 溆浦县| 永靖县| 汾阳市| 内黄县| 札达县| 交口县| 四平市| 柘荣县| 开封市| 建始县| 江安县| 恩平市| 泸水县| 盐亭县| 南丹县| 梁山县| 营口市| 云南省| 清远市| 永吉县| 长武县|