SQL BLOB
值在 Java 編程語言中的序列化映射關系。
SerialBlob
類提供一個根據 Blob
對象創建實例的構造方法。注意,在根據 Blob
對象構造 SerialBlob 對象之前,Blob
對象應該已經將 SQL Blob
值的數據置於客戶端上。SQL Blob
值的數據可以在客戶端上以字節數組(使用 Blob.getBytes
方法)或未解釋字節流的形式(使用 Blob.getBinaryStream
方法)實現。
SerialBlob
方法能夠以字節數組或流的形式復制 SerialBlob
對象。這些方法還可以在 SerialBlob
對象中查找給定模式的字節或 Blob
對象,並可以更新或截斷 Blob
對象。
構造方法摘要 | |
---|---|
SerialBlob(Blob blob) 根據給定 Blob 對象的序列化形式構造一個 SerialBlob 對象。 |
|
SerialBlob(byte[] b) 按照給定 byte 數組的序列化形式構造一個 SerialBlob 對象。 |
方法摘要 | |
---|---|
void |
free() 此方法釋放 Blob 對象及其占有的資源。 |
InputStream |
getBinaryStream() 以輸入流的形式返回此 SerialBlob 對象。 |
InputStream |
getBinaryStream(long pos, long length) 返回一個包含部分 Blob 值的 InputStream 對象,它從 pos 指定的字節開始,具有 length 個字節長度。 |
byte[] |
getBytes(long pos, int length) 將指定的字節數(從給定位置開始)從此 SerialBlob 對象復制到另一個字節數組。 |
long |
length() 獲取此 SerialBlob 對象字節數組中的字節數。 |
long |
position(Blob pattern, long start) 返回此 SerialBlob 對象中給定 Blob 對象開始的位置,搜索從指定位置開始。 |
long |
position(byte[] pattern, long start) 返回在此 SerialBlob 對象中給定模式的字節開始的位置,搜索從指定的位置開始。 |
OutputStream |
setBinaryStream(long pos) 獲取用於寫入此 Blob 對象所表示的 BLOB 值的流。 |
int |
setBytes(long pos, byte[] bytes) 將給定字節數組寫入此 Blob 對象表示的 BLOB 值(從位置 pos 處開始),並返回寫入的字節數。 |
int |
setBytes(long pos, byte[] bytes, int offset, int length) 將所有或部分給定的 byte 數組寫入此 Blob 對象表示的 BLOB 值中,並返回寫入的字節數。 |
void |
truncate(long length) 截取此 Blob 對象表示的 BLOB 值,使其長度為 len 個字節。 |
SerialBlob
public SerialBlob(byte[] b) throws SerialException, SQLException
-
按照給定
byte
數組的序列化形式構造一個SerialBlob
對象。新的
SerialBlob
對象使用byte
數組中的數據進行初始化,因此允許未連接RowSet
對象無需接觸數據源即可建立序列化的Blob
對象。- 參數:
-
b
- 一個byte
數組,包含要序列化的Blob
對象的數據 - 拋出:
-
SerialException
- 如果在序列化期間發生錯誤 -
SQLException
- 如果發生 SQL 錯誤
SerialBlob
public SerialBlob(Blob blob) throws SerialException, SQLException
-
根據給定
Blob
對象的序列化形式構造一個SerialBlob
對象。新的
SerialBlob
對象使用Blob
對象中的數據進行初始化;因此,Blob
對象應該預先從數據庫將 SQLBLOB
值的數據置於客戶端上。否則,新SerialBlob
對象將不包含任何數據。- 參數:
-
blob
- 一個Blob
對象,根據該對象構造此SerialBlob
對象 ;此值不能為 null。 - 拋出:
-
SerialException
- 如果在序列化期間發生錯誤 -
SQLException
- 如果傳遞給此構造方法的Blob
為null
。 - 另請參見:
-
Blob
getBytes
public byte[] getBytes(long pos, int length) throws SerialException
-
將指定的字節數(從給定位置開始)從此
SerialBlob
對象復制到另一個字節數組。注意,如果要復制的給定字節數大於此
SerialBlob
對象的字節數組的長度,則將其縮短為該數組的長度。 -
- 參數:
-
pos
- 此SerialBlob
對象中要復制的第一個字節的順序位置;編號從1
開始;不得小於1
並且必須小於或等於此SerialBlob
對象的長度 -
length
- 要復制的字節數 - 返回:
-
一個字節數組,它是此
SerialBlob
對象一個區域的副本,從給定位置開始並且包含給定的連續字節數 - 拋出:
-
SerialException
- 如果給定開始位置超出限制 - 另請參見:
-
Blob.setBytes(long, byte[])
詳細見:https://www.oschina.net/uploads/doc/javase-6-doc-api-zh_CN/javax/sql/rowset/serial/SerialBlob.html