Most visited

Recently visited

Added in API level 1

Blob

public interface Blob

java.sql.Blob


在SQL的Java TM编程语言的表示(映射) BLOB值。 SQL BLOB是一种内置类型,它将二进制大对象作为列值存储在数据库表的一行中。 默认情况下,驱动程序使用SQL locator(BLOB)实现Blob ,这意味着Blob对象包含一个指向SQL BLOB数据的逻辑指针,而不是数据本身。 一个Blob对象在创建事务期间有效。

方法在接口ResultSetCallableStatement ,并PreparedStatement ,如getBlobsetBlob允许编程人员访问SQL BLOB值。 Blob接口提供了获取SQL BLOB (二进制大对象)值的长度的方法,用于在客户机上实现BLOB值,并确定BLOB值内字节模式的位置。 此外,该接口还具有更新BLOB值的方法。

如果JDBC驱动程序支持数据类型,则必须完全实现 Blob接口上的所有方法。

Summary

Public methods

abstract void free()

此方法释放 Blob对象并释放它拥有的资源。

abstract InputStream getBinaryStream(long pos, long length)

返回一个 InputStream对象,其中包含部分 Blob值,从pos指定的字节开始,长度为字节长度。

abstract InputStream getBinaryStream()

以流的 BLOB检索此 Blob实例指定的 BLOB值。

abstract byte[] getBytes(long pos, int length)

检索的所有或部分 BLOB值,这 Blob对象表示,如字节数组。

abstract long length()

返回此 Blob对象指定的 BLOB值中的字节数。

abstract long position(Blob pattern, long start)

检索 pattern开始的 Blob对象指定的 BLOB值中的字节位置。

abstract long position(byte[] pattern, long start)

检索指定的字节数组 patternBlob对象表示的 BLOB值内开始的字节位置。

abstract OutputStream setBinaryStream(long pos)

检索可用于写入 Blob对象所表示的 BLOB值的流。

abstract int setBytes(long pos, byte[] bytes, int offset, int len)

将给定的 byte数组的全部或部分写入 Blob对象表示的 BLOB值,并返回写入的字节数。

abstract int setBytes(long pos, byte[] bytes)

将给定的字节数组写入 Blob对象表示的 BLOB值,从位置 pos开始,并返回写入的字节数。

abstract void truncate(long len)

截断 Blob对象表示的 BLOB值的长度为 len个字节。

Public methods

free

Added in API level 9
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

getBinaryStream

Added in API level 9
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

getBinaryStream

Added in API level 1
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

也可以看看:

getBytes

Added in API level 1
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

也可以看看:

length

Added in API level 1
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

position

Added in API level 1
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

position

Added in API level 1
long position (byte[] pattern, 
                long start)

检索指定的字节数组patternBlob对象表示的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

setBinaryStream

Added in API level 1
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

也可以看看:

setBytes

Added in API level 1
int setBytes (long pos, 
                byte[] bytes, 
                int offset, 
                int len)

将给定的byte数组的全部或部分写入Blob对象表示的BLOB值,并返回写入的字节数。 写作部分起始于posBLOB值; 来自给定字节数组的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

也可以看看:

setBytes

Added in API level 1
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

也可以看看:

truncate

Added in API level 1
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

Hooray!