接口 LobHandler
public interface LobHandler
Abstraction for handling large binary fields and large text fields in specific databases, no matter if represented as simple types or Large OBjects. Its main purpose is to isolate Oracle 9i's peculiar handling of LOBs inOracleLobHandler
; most other databases should be able to work with the providedDefaultLobHandler
.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 thejava.sql.Blob
andjava.sql.Clob
API completely.DefaultLobHandler
can also be configured to access LOBs usingPreparedStatement.setBlob/setClob
(e.g. for PostgreSQL), through setting the"wrapAsLob"
property.Unfortunately, Oracle 9i just accepts Blob/Clob instances created via its own proprietary BLOB/CLOB API, and additionally doesn't accept large streams for PreparedStatement's corresponding setter methods. Therefore, you need to use
OracleLobHandler
there, which uses Oracle's BLOB/CLOB API for both types of access. The Oracle 10g+ JDBC driver will work withDefaultLobHandler
as well, with some limitations in terms of LOB sizes depending on DBMS setup; as of Oracle 11g (or actually, using the 11g driver even against older databases), there should be no need to useOracleLobHandler
at all anymore.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):
- JDBC 4.0 driver (including Oracle 11g driver): Use
DefaultLobHandler
, potentially withstreamAsLob=true
if your database driver requires that hint when populating a LOB field. Fall back tocreateTemporaryLob=true
if you happen to run into LOB size limitations with your (Oracle) database setup. - Oracle 10g driver: Use
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. Alternatively, consider using the proprietaryOracleLobHandler
(see below). - Oracle 9i driver: Use
OracleLobHandler
with a connection-pool-specificNativeJdbcExtractor
. - PostgreSQL: Configure
DefaultLobHandler
withwrapAsLob=true
, and use that LobHandler to access OID columns (but not BYTEA) in your database tables. - For all other database drivers (and for non-LOB fields that might potentially turn into LOBs on some databases): Simply use a plain
DefaultLobHandler
.
- 从以下版本开始:
- 23.12.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
DefaultLobHandler
,OracleLobHandler
,ResultSet.getBlob(int)
,ResultSet.getClob(int)
,ResultSet.getBytes(int)
,ResultSet.getBinaryStream(int)
,ResultSet.getString(int)
,ResultSet.getAsciiStream(int)
,ResultSet.getCharacterStream(int)
- JDBC 4.0 driver (including Oracle 11g driver): Use
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 InputStream
getBlobAsBinaryStream(ResultSet rs, int columnIndex)
Retrieve the given column as binary stream from the given ResultSet.InputStream
getBlobAsBinaryStream(ResultSet rs, String columnName)
Retrieve the given column as binary stream from the given ResultSet.byte[]
getBlobAsBytes(ResultSet rs, int columnIndex)
Retrieve the given column as bytes from the given ResultSet.byte[]
getBlobAsBytes(ResultSet rs, String columnName)
Retrieve the given column as bytes from the given ResultSet.InputStream
getClobAsAsciiStream(ResultSet rs, int columnIndex)
Retrieve the given column as ASCII stream from the given ResultSet.InputStream
getClobAsAsciiStream(ResultSet rs, String columnName)
Retrieve the given column as ASCII stream from the given ResultSet.Reader
getClobAsCharacterStream(ResultSet rs, int columnIndex)
Retrieve the given column as character stream from the given ResultSet.Reader
getClobAsCharacterStream(ResultSet rs, String columnName)
Retrieve the given column as character stream from the given ResultSet.String
getClobAsString(ResultSet rs, int columnIndex)
Retrieve the given column as String from the given ResultSet.String
getClobAsString(ResultSet rs, String columnName)
Retrieve the given column as String from the given ResultSet.LobCreator
getLobCreator()
Create a newLobCreator
instance, i.e. a session for creating BLOBs and CLOBs.
方法详细资料
getBlobAsBytes
byte[] getBlobAsBytes(ResultSet rs, String columnName) throws SQLException
Retrieve the given column as bytes from the given ResultSet. Might simply invokeResultSet.getBytes
or work withResultSet.getBlob
, depending on the database and driver.- 参数:
rs
- the ResultSet to retrieve the content fromcolumnName
- the column name to use- 返回:
- the content as byte array, or
null
in case of SQL NULL - 抛出:
SQLException
- if thrown by JDBC methods- 另请参阅:
ResultSet.getBytes(int)
getBlobAsBytes
byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException
Retrieve the given column as bytes from the given ResultSet. Might simply invokeResultSet.getBytes
or work withResultSet.getBlob
, depending on the database and driver.- 参数:
rs
- the ResultSet to retrieve the content fromcolumnIndex
- the column index to use- 返回:
- the content as byte array, or
null
in case of SQL NULL - 抛出:
SQLException
- if thrown by JDBC methods- 另请参阅:
ResultSet.getBytes(int)
getBlobAsBinaryStream
InputStream getBlobAsBinaryStream(ResultSet rs, String columnName) throws SQLException
Retrieve the given column as binary stream from the given ResultSet. Might simply invokeResultSet.getBinaryStream
or work withResultSet.getBlob
, depending on the database and driver.- 参数:
rs
- the ResultSet to retrieve the content fromcolumnName
- the column name to use- 返回:
- the content as binary stream, or
null
in case of SQL NULL - 抛出:
SQLException
- if thrown by JDBC methods- 另请参阅:
ResultSet.getBinaryStream(int)
getBlobAsBinaryStream
InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException
Retrieve the given column as binary stream from the given ResultSet. Might simply invokeResultSet.getBinaryStream
or work withResultSet.getBlob
, depending on the database and driver.- 参数:
rs
- the ResultSet to retrieve the content fromcolumnIndex
- the column index to use- 返回:
- the content as binary stream, or
null
in case of SQL NULL - 抛出:
SQLException
- if thrown by JDBC methods- 另请参阅:
ResultSet.getBinaryStream(int)
getClobAsString
String getClobAsString(ResultSet rs, String columnName) throws SQLException
Retrieve the given column as String from the given ResultSet. Might simply invokeResultSet.getString
or work withResultSet.getClob
, depending on the database and driver.- 参数:
rs
- the ResultSet to retrieve the content fromcolumnName
- the column name to use- 返回:
- the content as String, or
null
in case of SQL NULL - 抛出:
SQLException
- if thrown by JDBC methods- 另请参阅:
ResultSet.getString(int)
getClobAsString
String getClobAsString(ResultSet rs, int columnIndex) throws SQLException
Retrieve the given column as String from the given ResultSet. Might simply invokeResultSet.getString
or work withResultSet.getClob
, depending on the database and driver.- 参数:
rs
- the ResultSet to retrieve the content fromcolumnIndex
- the column index to use- 返回:
- the content as String, or
null
in case of SQL NULL - 抛出:
SQLException
- if thrown by JDBC methods- 另请参阅:
ResultSet.getString(int)
getClobAsAsciiStream
InputStream getClobAsAsciiStream(ResultSet rs, String columnName) throws SQLException
Retrieve the given column as ASCII stream from the given ResultSet. Might simply invokeResultSet.getAsciiStream
or work withResultSet.getClob
, depending on the database and driver.- 参数:
rs
- the ResultSet to retrieve the content fromcolumnName
- the column name to use- 返回:
- the content as ASCII stream, or
null
in case of SQL NULL - 抛出:
SQLException
- if thrown by JDBC methods- 另请参阅:
ResultSet.getAsciiStream(int)
getClobAsAsciiStream
InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException
Retrieve the given column as ASCII stream from the given ResultSet. Might simply invokeResultSet.getAsciiStream
or work withResultSet.getClob
, depending on the database and driver.- 参数:
rs
- the ResultSet to retrieve the content fromcolumnIndex
- the column index to use- 返回:
- the content as ASCII stream, or
null
in case of SQL NULL - 抛出:
SQLException
- if thrown by JDBC methods- 另请参阅:
ResultSet.getAsciiStream(int)
getClobAsCharacterStream
Reader getClobAsCharacterStream(ResultSet rs, String columnName) throws SQLException
Retrieve the given column as character stream from the given ResultSet. Might simply invokeResultSet.getCharacterStream
or work withResultSet.getClob
, depending on the database and driver.- 参数:
rs
- the ResultSet to retrieve the content fromcolumnName
- the column name to use- 返回:
- the content as character stream
- 抛出:
SQLException
- if thrown by JDBC methods- 另请参阅:
ResultSet.getCharacterStream(int)
getClobAsCharacterStream
Reader getClobAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException
Retrieve the given column as character stream from the given ResultSet. Might simply invokeResultSet.getCharacterStream
or work withResultSet.getClob
, depending on the database and driver.- 参数:
rs
- the ResultSet to retrieve the content fromcolumnIndex
- the column index to use- 返回:
- the content as character stream
- 抛出:
SQLException
- if thrown by JDBC methods- 另请参阅:
ResultSet.getCharacterStream(int)
getLobCreator
LobCreator getLobCreator()
Create a newLobCreator
instance, i.e. a session for creating BLOBs and CLOBs. Needs to be closed after the created LOBs are not needed anymore - typically after statement execution or transaction completion.- 返回:
- the new LobCreator instance
- 另请参阅:
LobCreator.close()