JavaSky
          JavaBird
          posts - 8,  comments - 9,  trackbacks - 0
          CLOB字段的插入

          clob類型的數(shù)據(jù)直接insert可能會因為字符過長而出錯,所以要用對象形式插入.

          示例:

          首先,創(chuàng)建一個含CLOB字段的表:

          create table test (id INTEGER, content clob);

           

          然后插入空值

          String strSql = “INSERT INTO TEST(id,content) values(‘0001’,?) ”;

          con.setAutoCommit(false); //connConnection對象

          //創(chuàng)建并實例化一個CLOB對象

          CLOB clob = new CLOB((OracleConnection)con);

             clob = oracle.sql.CLOB.createTemporary((OracleConnection)con,true,1);

          //CLOB對象賦值

             clob.putString(1,formateSingleQuotes(Content));

             OracleConnection OCon = (OracleConnection)con;

             OraclePreparedStatement pstmt = (OraclePreparedStatement)OCon.prepareCall(strSql);

             pstmt.setCLOB(1,clob);

             int i = pstmt.executeUpdate();

             pstmt.close();

             OCon.commit();

             OCon = null;

          con = null;      

          Boolean flag = true;

          if(i <=0)

           {

                flag = false;

           }

           

          if (flag == true)

           {

                 out.print( "<script>alert('成功保存!'); </script>");

          }

           else

           {

                 out.print( "<script>alert('保存數(shù)據(jù)時出錯,請檢查你輸入的數(shù)據(jù)格式是否符合要求');self.history.back ();</script>");

           }

           

          注意:

          一定不要忘記引入包:import oracle.sql.*,oracle.jdbc.driver.*

           

          2.       CLOB類型的修改

           

          CLOB字段的修改除了sql語句外其他和插入相同

          String strSql = “UPDATE TEST set content=? Where Id=’0001’ ”;

          con.setAutoCommit(false); //connConnection對象

          //創(chuàng)建并實例化一個CLOB對象

          CLOB clob = new CLOB((OracleConnection)con);

             clob = oracle.sql.CLOB.createTemporary((OracleConnection)con,true,1);

          //CLOB對象賦值

             clob.putString(1,formateSingleQuotes(Content));

             OracleConnection OCon = (OracleConnection)con;

             OraclePreparedStatement pstmt = (OraclePreparedStatement)OCon.prepareCall(strSql);

             pstmt.setCLOB(1,clob);

             int i = pstmt.executeUpdate();

             pstmt.close();

             OCon.commit();

             OCon = null;

          con = null;      

          Boolean flag = true;

          if(i <=0)

           {

                flag = false;

           }

           

          if (flag == true)

           {

                 out.print( "<script>alert('成功保存!'); </script>");

          }

           else

           {

                 out.print( "<script>alert('保存數(shù)據(jù)時出錯,請檢查你輸入的數(shù)據(jù)格式是否符合要求');self.history.back ();</script>");

           }

          posted on 2012-01-18 17:15 JavaBird 閱讀(10380) 評論(2)  編輯  收藏 所屬分類: J2EE

          FeedBack:
          # re: Java處理(插入或修改)clob類型數(shù)據(jù)
          2013-05-22 14:07 | abbey
          垃圾,con怎么來的?  回復(fù)  更多評論
            
          # re: Java處理(插入或修改)clob類型數(shù)據(jù)
          2013-09-03 09:15 | jjj
          @abbey
          你個二貨,con是獲取數(shù)據(jù)庫連接好吧,這都要寫上去?   回復(fù)  更多評論
            

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


          網(wǎng)站導(dǎo)航:
           

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 临澧县| 房产| 吉林市| 白玉县| 仪陇县| 宁乡县| 将乐县| 二连浩特市| 新野县| 沿河| 教育| 塔城市| 中西区| 读书| 迭部县| 呼和浩特市| 小金县| 麟游县| 大新县| 泾川县| 江达县| 新田县| 博兴县| 平顺县| 大城县| 澄迈县| 应用必备| 中宁县| 宜章县| 敖汉旗| 锦屏县| 二连浩特市| 武威市| 桓台县| 嘉义县| 莲花县| 剑川县| 文化| 镇安县| 洪洞县| 辽源市|