andyj2ee

          java tec sky

          統(tǒng)計

          留言簿(4)

          activemq

          aop

          design pattern

          other blog

          spring

          workflow

          多線程

          軟件架構(gòu)師

          閱讀排行榜

          評論排行榜

          Oracle Blob/Clob 字段寫入時產(chǎn)生轉(zhuǎn)型異常Cast Exception

          CLOB clob = (CLOB)us.getStatisticsInfo();

          原因是
          java.sql.Blob不能強制傳喚成oracle.sql.BLOB

          解決方法如下:

          SerializableClob lob=(SerializableClob)us.getStatisticsInfo();
          CLOB lob2 = (CLOB)lob.getWrappedClob(); 
          Writer out = lob2.getCharacterOutputStream(); 
            

          public void testAdd() throws Exception {
                  
          byte[] buffer = new byte[1]; 
                  buffer[
          0= 1;
                  Session s 
          = null;
                  
          try 
                      s 
          = sf.openSession(); 
                      Transaction tx 
          = s.beginTransaction();
                      BizUserStatistics us
          = new BizUserStatistics();
                      us.setId(
          new Long(100));
                      us.setStatisticsInfo(Hibernate.createClob(
          " "));

                      s.save(us); 
                      s.flush(); 
                      s.refresh(us, LockMode.UPGRADE); 
          //            CLOB clob = (CLOB)us.getStatisticsInfo(); 
                      SerializableClob lob=(SerializableClob)us.getStatisticsInfo();
                      CLOB lob2 
          = (CLOB)lob.getWrappedClob();     
                      Writer out 
          = lob2.getCharacterOutputStream();
                      String fileName 
          = "d:/process_log.sql";
                      File f 
          = new File(fileName); 
                      FileInputStream fin 
          = new FileInputStream(f);
           
                      StringBuffer sb 
          = new StringBuffer();
                      
          for (int i = 0; i < 1000; i++){
                          sb.append(
          "<data>" + i + "</data>");
                      }

                      out.write(sb.toString());
                      out.close();
                      
                      s.flush(); 
                      tx.commit(); 
                      }
           catch (Exception e) {
                          e.printStackTrace(); 
                      }
           finally {
                          
          if (s != null)
                          
          try {
                          s.close(); 
                          }
           catch (Exception e){}
                      }


              }



          方向:分布式系統(tǒng)設計

          posted on 2006-02-14 16:35 java光環(huán) 閱讀(1245) 評論(0)  編輯  收藏 所屬分類: hibernate

          主站蜘蛛池模板: 全南县| 兴化市| 汝城县| 太湖县| 渭南市| 佛山市| 吉木萨尔县| 龙陵县| 绥棱县| 龙门县| 宁蒗| 英超| 扎鲁特旗| 崇明县| 吴江市| 南开区| 措勤县| 宽城| 潞西市| 泸西县| 巴青县| 夏邑县| 淅川县| 洪湖市| 石景山区| 安龙县| 临湘市| 永和县| 新乡县| 驻马店市| 元氏县| 扶沟县| 基隆市| 丰城市| 龙门县| 拉孜县| 布尔津县| 黄山市| 闸北区| 定远县| 太仓市|