public interface Blob
java.sql.Blob |
在SQL的Java TM编程语言的表示(映射) BLOB
值。 SQL BLOB
是一种内置类型,它将二进制大对象作为列值存储在数据库表的一行中。 默认情况下,驱动程序使用SQL locator(BLOB)
实现Blob
,这意味着Blob
对象包含一个指向SQL BLOB
数据的逻辑指针,而不是数据本身。 一个Blob
对象在创建事务期间有效。
方法在接口ResultSet
, CallableStatement
,并PreparedStatement
,如getBlob
和setBlob
允许编程人员访问SQL BLOB
值。 Blob
接口提供了获取SQL BLOB
(二进制大对象)值的长度的方法,用于在客户机上实现BLOB
值,并确定BLOB
值内字节模式的位置。 此外,该接口还具有更新BLOB
值的方法。
如果JDBC驱动程序支持数据类型,则必须完全实现 Blob
接口上的所有方法。
Public methods |
|
---|---|
abstract void |
free() 此方法释放 |
abstract InputStream |
getBinaryStream(long pos, long length) 返回一个 |
abstract InputStream |
getBinaryStream() 以流的 |
abstract byte[] |
getBytes(long pos, int length) 检索的所有或部分 |
abstract long |
length() 返回此 |
abstract long |
position(Blob pattern, long start) 检索 |
abstract long |
position(byte[] pattern, long start) 检索指定的字节数组 |
abstract OutputStream |
setBinaryStream(long pos) 检索可用于写入 |
abstract int |
setBytes(long pos, byte[] bytes, int offset, int len) 将给定的 |
abstract int |
setBytes(long pos, byte[] bytes) 将给定的字节数组写入 |
abstract void |
truncate(long len) 截断 |
void free ()
此方法释放Blob
对象并释放它拥有的资源。 一旦调用free
方法,该对象就无效。
在free
之后,任何尝试调用除free
之外的方法free
将导致SQLException
被抛出。 如果free
被多次调用,在后续调用free
被视为无操作。
Throws | |
---|---|
SQLException |
if an error occurs releasing the Blob's resources |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
InputStream getBinaryStream (long pos, long length)
返回包含部分 Blob
值的 InputStream
对象,从pos指定的字节开始,长度为字节长度。
Parameters | |
---|---|
pos |
long : the offset to the first byte of the partial value to be retrieved. The first byte in the Blob is at position 1 |
length |
long : the length in bytes of the partial value to be retrieved |
Returns | |
---|---|
InputStream |
InputStream through which the partial Blob value can be read. |
Throws | |
---|---|
SQLException |
if pos is less than 1 or if pos is greater than the number of bytes in the Blob or if pos + length is greater than the number of bytes in the Blob |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
InputStream getBinaryStream ()
以流的 BLOB
检索此 Blob
实例指定的 BLOB
值。
Returns | |
---|---|
InputStream |
a stream containing the BLOB data |
Throws | |
---|---|
SQLException |
if there is an error accessing the BLOB value |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
也可以看看:
byte[] getBytes (long pos, int length)
检索的所有或部分BLOB
值,这Blob
对象表示,如字节数组。 此byte
阵列包含从位置pos
开始的最多length
个连续字节。
Parameters | |
---|---|
pos |
long : the ordinal position of the first byte in the BLOB value to be extracted; the first byte is at position 1 |
length |
int : the number of consecutive bytes to be copied; the value for length must be 0 or greater |
Returns | |
---|---|
byte[] |
a byte array containing up to length consecutive bytes from the BLOB value designated by this Blob object, starting with the byte at position pos |
Throws | |
---|---|
SQLException |
if there is an error accessing the BLOB value; if pos is less than 1 or length is less than 0 |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
也可以看看:
long length ()
返回此 Blob
对象指定的 BLOB
值中的字节数。
Returns | |
---|---|
long |
length of the BLOB in bytes |
Throws | |
---|---|
SQLException |
if there is an error accessing the length of the BLOB |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
long position (Blob pattern, long start)
检索pattern
开始的Blob
对象指定的BLOB
值中的字节位置。 搜索从位置start
开始。
Parameters | |
---|---|
pattern |
Blob : the Blob object designating the BLOB value for which to search |
start |
long : the position in the BLOB value at which to begin searching; the first position is 1 |
Returns | |
---|---|
long |
the position at which the pattern begins, else -1 |
Throws | |
---|---|
SQLException |
if there is an error accessing the BLOB value or if start is less than 1 |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
long position (byte[] pattern, long start)
检索指定的字节数组pattern
在Blob
对象表示的BLOB
值内开始的字节位置。 搜索pattern
开始于位置start
。
Parameters | |
---|---|
pattern |
byte : the byte array for which to search |
start |
long : the position at which to begin searching; the first position is 1 |
Returns | |
---|---|
long |
the position at which the pattern appears, else -1 |
Throws | |
---|---|
SQLException |
if there is an error accessing the BLOB or if start is less than 1 |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
OutputStream setBinaryStream (long pos)
获取可用于写入的一个流BLOB
,该值Blob
对象表示。 流开始于位置pos
。 写入流的字节将覆盖在现有的字节Blob
在位置对象起始pos
。 如果年底Blob
同时写入流达到的值,那么长度Blob
值将增加以容纳额外的字节。
注意:如果为pos
指定的值大于BLOB
值的长度+ 1,则行为未定义。 某些JDBC驱动程序可能会抛出SQLException
而其他驱动程序可能会支持此操作。
Parameters | |
---|---|
pos |
long : the position in the BLOB value at which to start writing; the first position is 1 |
Returns | |
---|---|
OutputStream |
a java.io.OutputStream object to which data can be written |
Throws | |
---|---|
SQLException |
if there is an error accessing the BLOB value or if pos is less than 1 |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
也可以看看:
int setBytes (long pos, byte[] bytes, int offset, int len)
将给定的byte
数组的全部或部分写入Blob
对象表示的BLOB
值,并返回写入的字节数。 写作部分起始于pos
在BLOB
值; 来自给定字节数组的len
字节被写入。 字节阵列将覆盖在现有的字节Blob
对象开始在位置pos
。 如果在写入字节数组的过程中达到Blob
值的末尾,则会增加Blob
值的长度以容纳额外的字节。
注意:如果为pos
指定的值大于BLOB
值的长度+ 1,则行为未定义。 某些JDBC驱动程序可能会抛出SQLException
而其他驱动程序可能会支持此操作。
Parameters | |
---|---|
pos |
long : the position in the BLOB object at which to start writing; the first position is 1 |
bytes |
byte : the array of bytes to be written to this BLOB object |
offset |
int : the offset into the array bytes at which to start reading the bytes to be set |
len |
int : the number of bytes to be written to the BLOB value from the array of bytes bytes |
Returns | |
---|---|
int |
the number of bytes written |
Throws | |
---|---|
SQLException |
if there is an error accessing the BLOB value or if pos is less than 1 |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
也可以看看:
int setBytes (long pos, byte[] bytes)
将给定的字节数组写入Blob
对象表示的BLOB
值,从位置pos
开始,并返回写入的字节数。 字节阵列将覆盖在现有的字节Blob
对象开始在位置pos
。 如果的端Blob
而写入的字节的阵列达到值,则长度Blob
值将增加以容纳额外的字节。
注意:如果为pos
指定的值大于BLOB
值的长度+ 1,则行为未定义。 某些JDBC驱动程序可能会抛出SQLException
而其他驱动程序可能会支持此操作。
Parameters | |
---|---|
pos |
long : the position in the BLOB object at which to start writing; the first position is 1 |
bytes |
byte : the array of bytes to be written to the BLOB value that this Blob object represents |
Returns | |
---|---|
int |
the number of bytes written |
Throws | |
---|---|
SQLException |
if there is an error accessing the BLOB value or if pos is less than 1 |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |
也可以看看:
void truncate (long len)
截断此 Blob
对象表示的长度为 len
字节的 BLOB
值。
注意:如果为pos
指定的值大于BLOB
值的长度+ 1,则行为未定义。 某些JDBC驱动程序可能会抛出SQLException
而其他驱动程序可能会支持此操作。
Parameters | |
---|---|
len |
long : the length, in bytes, to which the BLOB value that this Blob object represents should be truncated |
Throws | |
---|---|
SQLException |
if there is an error accessing the BLOB value or if len is less than 0 |
SQLFeatureNotSupportedException |
if the JDBC driver does not support this method |