andyj2ee

          java tec sky

          統計

          留言簿(4)

          activemq

          aop

          design pattern

          other blog

          spring

          workflow

          多線程

          軟件架構師

          閱讀排行榜

          評論排行榜

          Oracle Blob/Clob 字段寫入時產生轉型異常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){}
                      }


              }



          方向:分布式系統設計

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

          主站蜘蛛池模板: 汉源县| 长顺县| 应用必备| 蒙城县| 棋牌| 海丰县| 遂川县| 肥乡县| 甘洛县| 甘谷县| 阳高县| 丹阳市| 茂名市| 镇安县| 扎囊县| 沧州市| 台湾省| 长白| 平山县| 昔阳县| 斗六市| 呼图壁县| 精河县| 化州市| 远安县| 新绛县| 尼玛县| 文山县| 浙江省| 常熟市| 军事| 绵阳市| 海林市| 贺兰县| 怀宁县| 五指山市| 奇台县| 崇阳县| 雷山县| 泽普县| 黎城县|