Class Blob
java.lang.Object
com.mysql.jdbc.Blob
- All Implemented Interfaces:
OutputStreamWatcher, Blob
The representation (mapping) in the JavaTM programming language of an SQL BLOB value. An SQL BLOB is a built-in type that stores a Binary Large Object
as a column value in a row of a database table. The driver implements Blob using an SQL locator(BLOB), which means that a Blob object contains a logical
pointer to the SQL BLOB data rather than the data itself. A Blob object is valid for the duration of the transaction in which is was created. Methods in
the interfaces ResultSet, CallableStatement, and PreparedStatement, such as getBlob and setBlob allow a programmer to access an SQL BLOB value. The Blob
interface provides methods for getting the length of an SQL BLOB (Binary Large Object) value, for materializing a BLOB value on the client, and for
determining the position of a pattern of bytes within a BLOB value. This class is new in the JDBC 2.0 API.
-
Constructor Summary
ConstructorsConstructorDescriptionBlob(byte[] data, ExceptionInterceptor exceptionInterceptor) Creates a BLOB encapsulating the given binary dataBlob(byte[] data, ResultSetInternalMethods creatorResultSetToSet, int columnIndexToSet) Creates an updatable BLOB that can update in-place (not implemented yet).Blob(ExceptionInterceptor exceptionInterceptor) Creates a Blob without data -
Method Summary
Modifier and TypeMethodDescriptionvoidfree()This method frees theBlobobject and releases the resources that it holds.Retrieves the BLOB designated by this Blob instance as a stream.getBinaryStream(long pos, long length) Returns anInputStreamobject that contains a partialBlobvalue, starting with the byte specified by pos, which is length bytes in length.byte[]getBytes(long pos, int length) Returns as an array of bytes, part or all of the BLOB value that this Blob object designates.longlength()Returns the number of bytes in the BLOB value designated by this Blob object.longposition(byte[] pattern, long start) longFinds the position of the given pattern in this BLOB.setBinaryStream(long indexToWriteAt) intsetBytes(long writeAt, byte[] bytes) intsetBytes(long writeAt, byte[] bytes, int offset, int length) voidstreamClosed(byte[] byteData) voidCalled when the OutputStream being watched has .close() calledvoidtruncate(long len) Truncates theBLOBvalue that thisBlobobject represents to belenbytes in length.
-
Constructor Details
-
Blob
Blob(ExceptionInterceptor exceptionInterceptor) Creates a Blob without data -
Blob
Blob(byte[] data, ExceptionInterceptor exceptionInterceptor) Creates a BLOB encapsulating the given binary data- Parameters:
data-
-
Blob
Blob(byte[] data, ResultSetInternalMethods creatorResultSetToSet, int columnIndexToSet) Creates an updatable BLOB that can update in-place (not implemented yet).- Parameters:
data-creatorResultSetToSet-columnIndexToSet-
-
-
Method Details
-
getBinaryStream
Retrieves the BLOB designated by this Blob instance as a stream.- Specified by:
getBinaryStreamin interfaceBlob- Returns:
- this BLOB represented as a binary stream of bytes.
- Throws:
SQLException- if a database error occurs
-
getBytes
Returns as an array of bytes, part or all of the BLOB value that this Blob object designates.- Specified by:
getBytesin interfaceBlob- Parameters:
pos- where to start the part of the BLOBlength- the length of the part of the BLOB you want returned.- Returns:
- the bytes stored in the blob starting at position
posand having a length oflength. - Throws:
SQLException- if a database error occurs
-
length
Returns the number of bytes in the BLOB value designated by this Blob object.- Specified by:
lengthin interfaceBlob- Returns:
- the length of this blob
- Throws:
SQLException- if a database error occurs
-
position
- Specified by:
positionin interfaceBlob- Throws:
SQLException- See Also:
-
position
Finds the position of the given pattern in this BLOB.- Specified by:
positionin interfaceBlob- Parameters:
pattern- the pattern to findstart- where to start finding the pattern- Returns:
- the position where the pattern is found in the BLOB, -1 if not found
- Throws:
SQLException- if a database error occurs
-
setBinaryStream
- Specified by:
setBinaryStreamin interfaceBlob- Throws:
SQLException- See Also:
-
setBytes
- Specified by:
setBytesin interfaceBlob- Throws:
SQLException- See Also:
-
setBytes
- Specified by:
setBytesin interfaceBlob- Throws:
SQLException- See Also:
-
streamClosed
public void streamClosed(byte[] byteData) - See Also:
-
streamClosed
Description copied from interface:OutputStreamWatcherCalled when the OutputStream being watched has .close() called- Specified by:
streamClosedin interfaceOutputStreamWatcher- See Also:
-
truncate
Truncates theBLOBvalue that thisBlobobject represents to belenbytes in length.Note: If the value specified for
lenis greater then the length+1 of theBLOBvalue then the behavior is undefined. Some JDBC drivers may throw aSQLExceptionwhile other drivers may support this operation. -
free
This method frees theBlobobject and releases the resources that it holds. The object is invalid once thefreemethod is called.After
freehas been called, any attempt to invoke a method other thanfreewill result in aSQLExceptionbeing thrown. Iffreeis called multiple times, the subsequent calls tofreeare treated as a no-op. -
getBinaryStream
Returns anInputStreamobject that contains a partialBlobvalue, starting with the byte specified by pos, which is length bytes in length.- Specified by:
getBinaryStreamin interfaceBlob- Parameters:
pos- the offset to the first byte of the partial value to be retrieved. The first byte in theBlobis at position 1length- the length in bytes of the partial value to be retrieved- Returns:
InputStreamthrough which the partialBlobvalue can be read.- Since:
- 1.6
-