In JDBC 2.0, java.sql.Blob is the mapping for the SQL BLOB (binary large object) type; java.sql.Clob is the mapping for the SQL CLOB (character large object) type.
java.sql.Blob and java.sql.Clob provide a logical pointer to the large object rather than a complete copy of the objects. Derby processes only one data page into memory at a time. The whole BLOB does not need to be processed and stored in memory just to access the first few bytes of the LOB object
In addition, casting between strings and BLOBs is not recommended because casting is platform and database dependent.
Derby uses unicode strings (2 byte characters), while other database products may use ASCII characters (1 byte per character). If various codepages are used, each character might need several bytes. A larger BLOB type might be necessary to accommodate a normal string in Derby. You should use CLOB types for storing strings.
Derby implements all of the methods for these JDBC 2.0 interfaces except for the set and get methods in CallableStatement interface.
Recommendations: Because the lifespan of a java.sql.Blob or java.sql.Clob ends when the transaction commits, turn off auto-commit with the java.sql.Blob or java.sql.Clob features.
Returns | Signature | Implementation Notes |
---|---|---|
InputStream | getBinaryStream() | |
byte[] | getBytes(long pos, int length) | Exceptions are raised if pos < 1, if pos is larger than the length of the , or if length <= 0. |
long | length() | |
long | position(byte[] pattern, long start) | Exceptions are raised if pattern == null, if start < 1, or if pattern is an array of length 0. |
long | position(Blob pattern, long start) | Exceptions are raised if pattern == null, if start < 1, if pattern has length 0, or if an exception is thrown when trying to read the first byte of pattern. |
Returns | Signature | Implementation Notes |
---|---|---|
InputStream | getAsciiStream() | |
Reader | getCharacterStream() | |
String | getSubString(long pos, int length) | Exceptions are raised if pos < 1, if pos is larger than the length of the Clob, or if length <= 0. |
long | length() | |
long | position(Clob searchstr, long start) | Exceptions are raised if searchStr == null or start < 1, if searchStr has length 0, or if an exception is thrown when trying to read the first char of searchStr. |
long | position(String searchstr, long start) | Exceptions are raised if searchStr == null or start < 1, or if the pattern is an empty string. |