Provides accessor methods for BLOBs and CLOBs, and acts as factory for LobCreator instances, to be used as sessions for creating BLOBs or CLOBs. LobCreators are typically instantiated for each statement execution or for each transaction; they are not thread-safe because they might track allocated database resources in order to free them after execution.
Most databases/drivers should be able to work with DefaultLobHandler,
which by default delegates to JDBC's direct accessor methods, avoiding the
java.sql.Blob and java.sql.Clob API completely.
DefaultLobHandler can also be configured to access LOBs using
PreparedStatement.setBlob/setClob (e.g. for PostgreSQL), through
setting the "wrapAsLob" property.
Of course, you need to declare different field types for each database. In Oracle, any binary content needs to go into a BLOB, and all character content beyond 4000 bytes needs to go into a CLOB. In MySQL, there is no notion of a CLOB type but rather a LONGTEXT type that behaves like a VARCHAR. For complete portability, use a LobHandler for fields that might typically require LOBs on some database because of the field size (take Oracle's numbers as a guideline).
Summarizing the recommended options (for actual LOB fields):
DefaultLobHandler,
potentially with streamAsLob=true if your database driver requires that
hint when populating a LOB field. Fall back to createTemporaryLob=true
if you happen to run into LOB size limitations with your (Oracle) database setup.
DefaultLobHandler with standard setup.
On Oracle 10.1, set the "SetBigStringTryClob" connection property; as of Oracle 10.2,
DefaultLobHandler should work with standard setup out of the box.
DefaultLobHandler with wrapAsLob=true,
and use that LobHandler to access OID columns (but not BYTEA) in your database tables.
DefaultLobHandler.
DefaultLobHandler, java.sql.ResultSet#getBlob , java.sql.ResultSet#getClob , java.sql.ResultSet#getBytes , java.sql.ResultSet#getBinaryStream , java.sql.ResultSet#getString , java.sql.ResultSet#getAsciiStream , java.sql.ResultSet#getCharacterStream
| Modifier and Type | Method and Description |
|---|---|
| public InputStream | Returns: the content as binary stream, ornull in case of SQL NULLthe ResultSet to retrieve the content from rs, String the column name to use columnName)Retrieve the given column as binary stream from the given ResultSet. |
| public InputStream | Returns: the content as binary stream, ornull in case of SQL NULLthe ResultSet to retrieve the content from rs, int the column index to use columnIndex)Retrieve the given column as binary stream from the given ResultSet. |
| public byte[] | Returns: the content as byte array, ornull in case of SQL NULLthe ResultSet to retrieve the content from rs, String the column name to use columnName)Retrieve the given column as bytes from the given ResultSet. |
| public byte[] | Returns: the content as byte array, ornull in case of SQL NULLthe ResultSet to retrieve the content from rs, int the column index to use columnIndex)Retrieve the given column as bytes from the given ResultSet. |
| public InputStream | Returns: the content as ASCII stream, ornull in case of SQL NULLthe ResultSet to retrieve the content from rs, String the column name to use columnName)Retrieve the given column as ASCII stream from the given ResultSet. |
| public InputStream | Returns: the content as ASCII stream, ornull in case of SQL NULLthe ResultSet to retrieve the content from rs, int the column index to use columnIndex)Retrieve the given column as ASCII stream from the given ResultSet. |
| public Reader | Returns: the content as character streamthe ResultSet to retrieve the content from rs, String the column name to use columnName)Retrieve the given column as character stream from the given ResultSet. |
| public Reader | Returns: the content as character streamthe ResultSet to retrieve the content from rs, int the column index to use columnIndex)Retrieve the given column as character stream from the given ResultSet. |
| public String | Returns: the content as String, ornull in case of SQL NULLthe ResultSet to retrieve the content from rs, String the column name to use columnName)Retrieve the given column as String from the given ResultSet. |
| public String | Returns: the content as String, ornull in case of SQL NULLthe ResultSet to retrieve the content from rs, int the column index to use columnIndex)Retrieve the given column as String from the given ResultSet. |
| public LobCreator | Returns: the new LobCreator instanceCreate a new |
| getBlobAsBinaryStream | back to summary |
|---|---|
| public InputStream getBlobAsBinaryStream(ResultSet rs, String columnName) throws SQLException Retrieve the given column as binary stream from the given ResultSet.
Might simply invoke
| |
| getBlobAsBinaryStream | back to summary |
|---|---|
| public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException Retrieve the given column as binary stream from the given ResultSet.
Might simply invoke
| |
| getBlobAsBytes | back to summary |
|---|---|
| public byte[] getBlobAsBytes(ResultSet rs, String columnName) throws SQLException Retrieve the given column as bytes from the given ResultSet.
Might simply invoke
| |
| getBlobAsBytes | back to summary |
|---|---|
| public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException Retrieve the given column as bytes from the given ResultSet.
Might simply invoke
| |
| getClobAsAsciiStream | back to summary |
|---|---|
| public InputStream getClobAsAsciiStream(ResultSet rs, String columnName) throws SQLException Retrieve the given column as ASCII stream from the given ResultSet.
Might simply invoke
| |
| getClobAsAsciiStream | back to summary |
|---|---|
| public InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException Retrieve the given column as ASCII stream from the given ResultSet.
Might simply invoke
| |
| getClobAsCharacterStream | back to summary |
|---|---|
| public Reader getClobAsCharacterStream(ResultSet rs, String columnName) throws SQLException Retrieve the given column as character stream from the given ResultSet.
Might simply invoke
| |
| getClobAsCharacterStream | back to summary |
|---|---|
| public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException Retrieve the given column as character stream from the given ResultSet.
Might simply invoke
| |
| getClobAsString | back to summary |
|---|---|
| public String getClobAsString(ResultSet rs, String columnName) throws SQLException Retrieve the given column as String from the given ResultSet.
Might simply invoke
| |
| getClobAsString | back to summary |
|---|---|
| public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException Retrieve the given column as String from the given ResultSet.
Might simply invoke
| |
| getLobCreator | back to summary |
|---|---|
| public LobCreator getLobCreator() Create a new
| |