Improve description of DefaultLobHandler in reference manual
Issue: SPR-12985
This commit is contained in:
committed by
Sam Brannen
parent
250aef81e4
commit
edc66d76af
@@ -4355,23 +4355,24 @@ You can provide SQL type information in several ways:
|
||||
|
||||
[[jdbc-lob]]
|
||||
==== Handling BLOB and CLOB objects
|
||||
You can store images, other binary objects, and large chunks of text. These large object
|
||||
are called BLOB for binary data and CLOB for character data. In Spring you can handle
|
||||
these large objects by using the JdbcTemplate directly and also when using the higher
|
||||
abstractions provided by RDBMS Objects and the `SimpleJdbc` classes. All of these
|
||||
approaches use an implementation of the `LobHandler` interface for the actual management
|
||||
of the LOB data. The `LobHandler` provides access to a `LobCreator` class, through the
|
||||
`getLobCreator` method, used for creating new LOB objects to be inserted.
|
||||
You can store images, other binary data, and large chunks of text in the database. These
|
||||
large objects are called BLOBs (Binary Large OBject) for binary data and CLOBs (Character
|
||||
Large OBject) for character data. In Spring you can handle these large objects by using
|
||||
the `JdbcTemplate` directly and also when using the higher abstractions provided by RDBMS
|
||||
Objects and the `SimpleJdbc` classes. All of these approaches use an implementation of
|
||||
the `LobHandler` interface for the actual management of the LOB (Large OBject) data. The
|
||||
`LobHandler` provides access to a `LobCreator` class, through the `getLobCreator` method,
|
||||
used for creating new LOB objects to be inserted.
|
||||
|
||||
The `LobCreator/LobHandler` provides the following support for LOB input and output:
|
||||
|
||||
* BLOB
|
||||
* byte[] -- getBlobAsBytes and setBlobAsBytes
|
||||
* InputStream -- getBlobAsBinaryStream and setBlobAsBinaryStream
|
||||
** `byte[]` -- `getBlobAsBytes` and `setBlobAsBytes`
|
||||
** `InputStream` -- `getBlobAsBinaryStream` and `setBlobAsBinaryStream`
|
||||
* CLOB
|
||||
* String -- getClobAsString and setClobAsString
|
||||
* InputStream -- getClobAsAsciiStream and setClobAsAsciiStream
|
||||
* Reader -- getClobAsCharacterStream and setClobAsCharacterStream
|
||||
** `String` -- `getClobAsString` and `setClobAsString`
|
||||
** `InputStream` -- `getClobAsAsciiStream` and `setClobAsAsciiStream`
|
||||
** `Reader` -- `getClobAsCharacterStream` and `setClobAsCharacterStream`
|
||||
|
||||
The next example shows how to create and insert a BLOB. Later you will see how to read
|
||||
it back from the database.
|
||||
@@ -4407,10 +4408,25 @@ dependency injection.
|
||||
clobReader.close();
|
||||
----
|
||||
|
||||
<1> Pass in the lobHandler that in this example is a plain `DefaultLobHandler`
|
||||
<1> Pass in the `lobHandler` that in this example is a plain `DefaultLobHandler`.
|
||||
<2> Using the method `setClobAsCharacterStream`, pass in the contents of the CLOB.
|
||||
<3> Using the method `setBlobAsBinaryStream`, pass in the contents of the BLOB.
|
||||
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
If you invoke the `setBlobAsBinaryStream`, `setClobAsAsciiStream`, or
|
||||
`setClobAsCharacterStream` method on the `LobCreator` returned from
|
||||
`DefaultLobHandler.getLobCreator()`, you can optionally specify a negative value for the
|
||||
`contentLength` argument. If the specified content length is negative, the
|
||||
`DefaultLobHandler` will use the JDBC 4.0 variants of the set-stream methods without a
|
||||
length parameter; otherwise, it will pass the specified length on to the driver.
|
||||
|
||||
Consult the documentation for the JDBC driver in use to verify support for streaming a
|
||||
LOB without providing the content length.
|
||||
====
|
||||
|
||||
|
||||
Now it's time to read the LOB data from the database. Again, you use a `JdbcTemplate`
|
||||
with the same instance variable `lobHandler` and a reference to a `DefaultLobHandler`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user