Package java.sql
Interface Blob
public interface Blob
A Java interface representing the SQL
BLOB type.
An SQL BLOB type stores a large array of binary data (bytes) as the
value in a column of a database.
The java.sql.Blob interface provides methods for setting and
retrieving data in the Blob, for querying Blob data length,
and for searching for data within the Blob.
-
Method Summary
Modifier and Type Method Description voidfree()Frees any resources held by this blob.InputStreamgetBinaryStream()Retrieves thisBlobobject as a binary stream.InputStreamgetBinaryStream(long pos, long length)Retrieveslengthbytes from thisBlob, starting at 1-based offsetpos, and returns them as a binary stream.byte[]getBytes(long pos, int length)Gets a portion of the value of thisBlobas an array of bytes.longlength()Gets the number of bytes in thisBlobobject.longposition(byte[] pattern, long start)Search for the position in thisBlobat which the specified pattern begins, starting at a specified position within theBlob.longposition(Blob pattern, long start)Search for the position in thisBlobat which a specified pattern begins, starting at a specified position within theBlob.OutputStreamsetBinaryStream(long pos)Gets a stream that can be used to write binary data to thisBlob.intsetBytes(long pos, byte[] theBytes)Writes a specified array of bytes to thisBlobobject, starting at a specified position.intsetBytes(long pos, byte[] theBytes, int offset, int len)Writes a portion of a specified byte array to thisBlob.voidtruncate(long len)Truncate the value of thisBlobobject to a specified length in bytes.
-
Method Details
-
getBinaryStream
Retrieves thisBlobobject as a binary stream.- Returns:
- a binary
InputStreamgiving access to theBlobdata. - Throws:
SQLException- if an error occurs accessing theBlob.
-
getBinaryStream
Retrieveslengthbytes from thisBlob, starting at 1-based offsetpos, and returns them as a binary stream.- Returns:
- a binary
InputStreamgiving access to theBlobdata. - Throws:
SQLException- if an error occurs accessing theBlob.
-
getBytes
Gets a portion of the value of thisBlobas an array of bytes.- Parameters:
pos- the position of the first byte in theBlobto get, where the first byte in theBlobhas position 1.length- the number of bytes to get.- Returns:
- a byte array containing the data from the
Blob, starting atposand is up tolengthbytes long. - Throws:
SQLException- if an error occurs accessing theBlob.
-
length
Gets the number of bytes in thisBlobobject.- Returns:
- a
longvalue with the length of theBlobin bytes. - Throws:
SQLException- if an error occurs accessing theBlob.
-
position
Search for the position in thisBlobat which a specified pattern begins, starting at a specified position within theBlob.- Parameters:
pattern- aBlobcontaining the pattern of data to search for in thisBlob.start- the position within thisBlobto start the search, where the first position in theBlobis1.- Returns:
- a
longvalue with the position at which the pattern begins. Returns-1if the pattern is not found in thisBlob. - Throws:
SQLException- if an error occurs accessing theBlob.
-
position
Search for the position in thisBlobat which the specified pattern begins, starting at a specified position within theBlob.- Parameters:
pattern- a byte array containing the pattern of data to search for in thisBlob.start- the position within thisBlobto start the search, where the first position in theBlobis1.- Returns:
- a
longvalue with the position at which the pattern begins. Returns-1if the pattern is not found in thisBlob. - Throws:
SQLException- if an error occurs accessing theBlob.
-
setBinaryStream
Gets a stream that can be used to write binary data to thisBlob.- Parameters:
pos- the position within thisBlobat which to start writing, where the first position in theBlobis1.- Returns:
- a binary
InputStreamwhich can be used to write data into theBlobstarting at the specified position. - Throws:
SQLException- if an error occurs accessing theBlob.
-
setBytes
Writes a specified array of bytes to thisBlobobject, starting at a specified position. Returns the number of bytes written.- Parameters:
pos- the position within thisBlobat which to start writing, where the first position in theBlobis1.theBytes- an array of bytes to write into theBlob.- Returns:
- an integer containing the number of bytes written to the
Blob. - Throws:
SQLException- if an error occurs accessing theBlob.
-
setBytes
Writes a portion of a specified byte array to thisBlob. Returns the number of bytes written.- Parameters:
pos- the position within thisBlobat which to start writing, where the first position in theBlobis1.theBytes- an array of bytes to write into theBlob.offset- the offset into the byte array from which to start writing data - the first byte in the array has offset0.len- the length of data to write in number of bytes.- Returns:
- an integer containing the number of bytes written to the
Blob. - Throws:
SQLException- if an error occurs accessing theBlob.
-
truncate
Truncate the value of thisBlobobject to a specified length in bytes.- Parameters:
len- the length of data in bytes after which thisBlobis to be truncated.- Throws:
SQLException- if an error occurs accessing theBlob.
-
free
Frees any resources held by this blob. Afterfreeis called, calling method other thanfreewill throwSQLException(callingfreerepeatedly will do nothing).- Throws:
SQLException
-