I have a DB procedure which returns a BLOB. Can anyone tell me how to manipulate the BLOB? Is there any specific API for this?
To represent a BLOB data type, we use K, M, and G characters that represent the multiples of 1024, 1024*1024, 1024*1024*1024, respectively. The lifespan of a BLOB ends when a transaction commits. We should use the BLOB data type if we want to store very large binary values.
A BLOB (binary large object) is a varying-length binary string that can be up to 2,147,483,647 characters long. Like other binary types, BLOB strings are not associated with a code page. In addition, BLOB strings do not hold character data.
A longblob is just an array of bytes up to a length of 2^32 - 1.
Is there any specific API for this ?
Sure, the JDBC API.
You get hold of the Blob
instance just as you get hold of any value from a result set. You should then use the get...
- and set...
methods on this Blob
.
Here you basically have two options:
Work with a byte-array:
byte[]
containing the data through Blob.getBytes
Blob.setBytes
.Work with InputStream
/ OutputStream
:
InputStream
through Blob.getBinaryStream
Blob.setBinaryStream
.
An alternative approach is to skip messing with Blob
in the first place, and instead use the second approach (with streams) directly through the ResultSet
-interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With