Rising Sun

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            148 隨筆 :: 0 文章 :: 22 評論 :: 0 Trackbacks

          [http://blog.javascud.org/rss.php?blogId=25&categoryId=32]
          測試類 ClobTest.java

          /**
           *
           */
          package com.chinantn.test;

          import java.io.Writer;
          import java.sql.Clob;

          import oracle.sql.CLOB;

          import org.hibernate.Hibernate;
          import org.hibernate.LockMode;
          import org.hibernate.Session;
          import org.hibernate.Transaction;
          import org.hibernate.lob.SerializableClob;

          import com.chinantn.sdfda.common.hibernate.HibernateSessionFactory;
          import com.chinantn.sdfda.content.domain.Test;

          /**
           * @author Administrator
           *
           */
          public class ClobTest {

           /**
            * @param args
            */
           public static void main(String[] args) throws Exception{
            Session s = HibernateSessionFactory.currentSession();
            /*//寫CLOB
            Transaction tx = s.beginTransaction();
            Test t = new Test();
            t.setContent(Hibernate.createClob(" "));
            s.save(t);
            s.flush();
            s.refresh(t,LockMode.UPGRADE);
            //CLOB clob = (CLOB)t.getContent();
            
            SerializableClob sc= (SerializableClob)t.getContent();
            Clob wrapclob = sc.getWrappedClob();
            CLOB clob = (CLOB)wrapclob;
            
            
          // Writer cout = clob.getCharacterOutputStream();
          //用文件上傳到 clob 字段是亂碼 (中文)//
          // File file = new File("C:\\1.txt");//修改你要存如的文本
          // FileInputStream fin = new FileInputStream(file);
          //int read;
          //while((read = fin.read())!= -1){
           //        cout.write(read);
           / }
           //fin.close();
          //
          //下面是正常
            StringBuffer sb = new StringBuffer();
            for(int i = 0; i < 10000; i ++){
             sb.append("我要忍!!!");
            }
            w.write(sb.toString());
            w.flush();
            w.close();
            tx.commit();*/
            /*
            //讀CLOB
            Test t = (Test)s.get(Test.class,"109a1b7438[142bece]-8000");
            Clob clob = t.getContent();
            if(clob != null){
             String clobStr = clob.getSubString(1,(int)clob.length());
             System.out.println(clobStr.length());
             System.out.println(clobStr);
            }*/
            
            //更新CLOB
            Transaction tx = s.beginTransaction();
            Test t = (Test)s.get(Test.class,"109a1b7438[142bece]-8000");
            t.setContent(Hibernate.createClob(" "));
            s.update(t);
            s.flush();
            s.refresh(t,LockMode.UPGRADE);
            
            SerializableClob sc= (SerializableClob)t.getContent();
            Clob wrapclob = sc.getWrappedClob();
            CLOB clob = (CLOB)wrapclob;
            
            Writer w = clob.getCharacterOutputStream();
            StringBuffer sb = new StringBuffer();
            for(int i = 0; i < 1000; i ++){
             sb.append("我很努力!!!");
            }
            w.write(sb.toString());
            w.flush();
            w.close();
            tx.commit();
            
            if(clob != null){
             String clobStr = clob.getSubString(1,(int)clob.length());
             System.out.println(clobStr.length());
             System.out.println(clobStr);
            }
            HibernateSessionFactory.closeSession();

           }

          }

          posted on 2007-08-13 09:58 brock 閱讀(1960) 評論(1)  編輯  收藏

          評論

          # re: Hibernate3 存取Oracle數(shù)據(jù)庫 CLOB大對象 2012-05-28 10:16 輔導(dǎo)輔導(dǎo)
          輔導(dǎo)輔導(dǎo)輔導(dǎo)輔導(dǎo)輔導(dǎo)輔導(dǎo)費(fèi)  回復(fù)  更多評論
            


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 山西省| 海安县| 依兰县| 望江县| 长宁县| 黑龙江省| 当雄县| 耿马| 根河市| 东至县| 海伦市| 景德镇市| 安福县| 龙江县| 叶城县| 大埔区| 黔西县| 平潭县| 乌恰县| 南宁市| 丰县| 崇信县| 临清市| 西贡区| 西平县| 读书| 钟祥市| 石渠县| 安国市| 琼海市| 台东县| 沂水县| 普定县| 吉木乃县| 瑞昌市| 吉安县| 夏津县| 长汀县| 垦利县| 常州市| 珲春市|