信念樹下
          --夢(mèng)想只是不能實(shí)現(xiàn)的,想要實(shí)現(xiàn)就要有計(jì)劃。
          posts - 5,comments - 0,trackbacks - 0
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          搜索

          •  

          最新評(píng)論

          ORACLE中的大對(duì)象: 
          LONG: 可變長的字符串?dāng)?shù)據(jù),最長2G,LONG具有VARCHAR2列的特性,可以存儲(chǔ)長文本一個(gè)表中最多一個(gè)LONG列
          LONG RAW: 可變長二進(jìn)制數(shù)據(jù),最長2G
          CLOB:  字符大對(duì)象Clob 用來存儲(chǔ)單字節(jié)的字符數(shù)據(jù)
          NCLOB: 用來存儲(chǔ)多字節(jié)的字符數(shù)據(jù)
          BLOB: 用于存儲(chǔ)二進(jìn)制數(shù)據(jù)
          BFILE: 存儲(chǔ)在文件中的二進(jìn)制數(shù)據(jù),這個(gè)文件中的數(shù)據(jù)只能被只讀訪。但該文件不包含在數(shù)據(jù)庫內(nèi)。bfile字段實(shí)際的文件存儲(chǔ)在文件系統(tǒng)中,字段中存儲(chǔ)的是文件定位指針.bfile對(duì)oracle來說是只讀的,也不參與事務(wù)性控制和數(shù)據(jù)恢復(fù).   
          CLOB,NCLOB,BLOB都是內(nèi)部的LOB(Large Object)類型,最長4G,沒有LONG只能有一列的限制。

          要保存圖片、文本文件、Word文件各自最好用哪種數(shù)據(jù)類型?
          --BLOB最好,LONG RAW也不錯(cuò),但Long是oracle將要廢棄的類型,因此建議用BLOB。
          對(duì)CLOB與BLOB對(duì)象的操作
              1.  查詢(GET) 

               查詢CLOB     

              //獲得數(shù)據(jù)庫連接  
              Connection con = ConnectionFactory.getConnection();  
              con.setAutoCommit(false);  
              Statement st = con.createStatement();  
              //不需要“for update”  
              ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1");  
              if (rs.next())  
              {  
                  java.sql.Clob clob = rs.getClob("CLOBATTR");  
                  Reader inStream = clob.getCharacterStream();  
                  char[] c = new char[(int) clob.length()];  
                  inStream.read(c);  
                  //data是讀出并需要返回的數(shù)據(jù),類型是String  
                  data = new String(c);  
                  inStream.close();  
              }  
              inStream.close();  
              con.commit();  
              con.close();
              
              查詢BLOB
              Connection con = ConnectionFactory.getConnection(); 
              con.setAutoCommit(false);  
              Statement st = con.createStatement();  
              //不需要“for update”  
              ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1");  
              if (rs.next())  
              {  
                  java.sql.Blob blob = rs.getBlob("BLOBATTR");  
                  InputStream inStream = blob.getBinaryStream();  
                  //data是讀出并需要返回的數(shù)據(jù),類型是byte[]  
                  data = new byte[input.available()];  
                  inStream.read(data);  
                  inStream.close();  
              }  
              inStream.close();  
              con.commit();  
              con.close();  
           
              2.  插入(INSERT)

                  
               插入CLOB
           
              //獲得數(shù)據(jù)庫連接  
              Connection con = ConnectionFactory.getConnection();  
              con.setAutoCommit(false);  
              Statement st = con.createStatement();  
              //插入一個(gè)空對(duì)象empty_clob()  
              st.executeUpdate("insert into TESTCLOB (ID, NAME, CLOBATTR) values (1, "thename", empty_clob())");  
              //鎖定數(shù)據(jù)行進(jìn)行更新,注意“for update”語句  
              ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1 for update");  
              if (rs.next())  
              {  
                  //得到j(luò)ava.sql.Clob對(duì)象后強(qiáng)制轉(zhuǎn)換為oracle.sql.CLOB  
                  oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob("CLOBATTR");  
                  Writer outStream = clob.getCharacterOutputStream();  
                  //data是傳入的字符串,定義:String data  
                  char[] c = data.toCharArray();  
                  outStream.write(c, 0, c.length);  
              }  
              outStream.flush();  
              outStream.close();  
              con.commit();  
              con.close();       
              插入BLOB 
              //獲得數(shù)據(jù)庫連接  
              Connection con = ConnectionFactory.getConnection();  
              con.setAutoCommit(false);  
              Statement st = con.createStatement();  
              //插入一個(gè)空對(duì)象empty_blob()  
              st.executeUpdate("insert into TESTBLOB (ID, NAME, BLOBATTR) values (1, "thename", empty_blob())");  
              //鎖定數(shù)據(jù)行進(jìn)行更新,注意“for update”語句  
              ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1 for update");  
              if (rs.next())  
              {  
                  //得到j(luò)ava.sql.Blob對(duì)象后強(qiáng)制轉(zhuǎn)換為oracle.sql.BLOB  
                  oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("BLOBATTR");  
                  OutputStream outStream = blob.getBinaryOutputStream();  
                  //data是傳入的byte數(shù)組,定義:byte[] data  
                  outStream.write(data, 0, data.length);  
              }  
              outStream.flush();  
              outStream.close();  
              con.commit();  
              con.close();  

          posted on 2010-09-29 08:19 三角形 閱讀(2472) 評(píng)論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 扬州市| 安西县| 光山县| 玉溪市| 宁明县| 射阳县| 湟源县| 襄樊市| 渭源县| 浦城县| 当涂县| 谢通门县| 张家港市| 营山县| 天等县| 桂东县| 上犹县| 三门县| 上杭县| 临江市| 塔城市| 东光县| 黄骅市| 什邡市| 弥勒县| 扬中市| 波密县| 启东市| 简阳市| 瑞昌市| 民丰县| 玉环县| 离岛区| 通河县| 阳朔县| 龙陵县| 文山县| 河北区| 肃宁县| 鹤岗市| 安义县|