JAVA處理Clob大對象

來源:互聯網
上載者:User

BLOB就是使用二進位儲存資料。 如:儲存位元影像。 CLOB使用CHAR來儲存資料。 如:儲存XML文檔。

 

1、建立Clob對象
下面的程式碼片段說明了如何建立一個Clob對象,其中rs是一個ResultSet對象:
Clob clob = rs.getClob(1);
變數clob現在可以被用於在CLOB值上執行操作,而假設這CLOB值儲存在結果集rs的第一列中。

或

FileInputStream fis1 = new FileInputStream("D:/test.txt");
pstmt.setBinaryStream(1, fis1, fis1.available());
 

2、物化Clob資料
和物化Blob的方式一樣。不過Clob介面提供了三種方法達到將CLOB作

為一個Java對象的形式儲存在客戶的記憶體中。
①使用getAsiiStream把CLOB值物化為一個包含Ascii位元組的字元流。
Clob notes = rs.getClob(“NOTES”);
java.io.InputStream in = notes.getAsciiStream();
byte b = in.read();

②    使用getCharacterStream把CLOB值物化為一個Unicode字元流。
Clob notes = rs.getClob(“NOTES”);
java.io.Reader reader = notes.getCharacterStream();
int c = reader.read();

③    使用getSubString將CLOB值的全部或者部分化為一個String對象。

Clob notes = rs.getClob(4);
String substring= notes.getSubString(10,5);

或者

long len =notes.length();
String substring = notes.getSubString(1,(int)len);

3、儲存、更新Clob對象和儲存、更新Blob對象類似。(具體見再上次的部落格) 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.