类 DefaultLobHandler
- java.lang.Object
- org.springframework.jdbc.support.lob.AbstractLobHandler
- org.springframework.jdbc.support.lob.DefaultLobHandler
- 所有已实现的接口:
LobHandler
public class DefaultLobHandler extends AbstractLobHandler
Default implementation of theLobHandler
interface. Invokes the direct accessor methods thatjava.sql.ResultSet
andjava.sql.PreparedStatement
offer.By default, incoming streams are going to be passed to the appropriate
setBinary/Ascii/CharacterStream
method on the JDBC driver'sPreparedStatement
. If the specified content length is negative, this handler 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.This LobHandler should work for any JDBC driver that is JDBC compliant in terms of the spec's suggestions regarding simple BLOB and CLOB handling. This does not apply to Oracle 9i's drivers at all; as of Oracle 10g, it does work but may still come with LOB size limitations. Consider using recent Oracle drivers even when working against an older database server. See the
LobHandler
javadoc for the full set of recommendations.Some JDBC drivers require values with a BLOB/CLOB target column to be explicitly set through the JDBC
setBlob
/setClob
API: for example, PostgreSQL's driver. Switch the"wrapAsLob"
property to "true" when operating against such a driver.On JDBC 4.0, this LobHandler also supports streaming the BLOB/CLOB content via the
setBlob
/setClob
variants that take a stream argument directly. Consider switching the"streamAsLob"
property to "true" when operating against a fully compliant JDBC 4.0 driver.Finally, primarily as a direct equivalent to
OracleLobHandler
, this LobHandler also supports the creation of temporary BLOB/CLOB objects. Consider switching the"createTemporaryLob"
property to "true" when "streamAsLob" happens to run into LOB size limitations.See the
LobHandler
interface javadoc for a summary of recommendations.- 从以下版本开始:
- 04.12.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
ResultSet.getBytes(int)
,ResultSet.getBinaryStream(int)
,ResultSet.getString(int)
,ResultSet.getAsciiStream(int)
,ResultSet.getCharacterStream(int)
,PreparedStatement.setBytes(int, byte[])
,PreparedStatement.setBinaryStream(int, java.io.InputStream, int)
,PreparedStatement.setString(int, java.lang.String)
,PreparedStatement.setAsciiStream(int, java.io.InputStream, int)
,PreparedStatement.setCharacterStream(int, java.io.Reader, int)
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected class
DefaultLobHandler.DefaultLobCreator
Default LobCreator implementation as an inner class.
构造器概要
构造器 构造器 说明 DefaultLobHandler()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 InputStream
getBlobAsBinaryStream(ResultSet rs, int columnIndex)
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.InputStream
getClobAsAsciiStream(ResultSet rs, int columnIndex)
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.String
getClobAsString(ResultSet rs, int columnIndex)
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.void
setCreateTemporaryLob(boolean createTemporaryLob)
Specify whether to copy a byte array / String into a temporary JDBC Blob / Clob object created through the JDBC 4.0createBlob
/createClob
methods.void
setStreamAsLob(boolean streamAsLob)
Specify whether to submit a binary stream / character stream to the JDBC driver as explicit LOB content, using the JDBC 4.0setBlob
/setClob
method with a stream argument.void
setWrapAsLob(boolean wrapAsLob)
Specify whether to submit a byte array / String to the JDBC driver wrapped in a JDBC Blob / Clob object, using the JDBCsetBlob
/setClob
method with a Blob / Clob argument.从类继承的方法 org.springframework.jdbc.support.lob.AbstractLobHandler
getBlobAsBinaryStream, getBlobAsBytes, getClobAsAsciiStream, getClobAsCharacterStream, getClobAsString
构造器详细资料
DefaultLobHandler
public DefaultLobHandler()
方法详细资料
setWrapAsLob
public void setWrapAsLob(boolean wrapAsLob)
Specify whether to submit a byte array / String to the JDBC driver wrapped in a JDBC Blob / Clob object, using the JDBCsetBlob
/setClob
method with a Blob / Clob argument.Default is "false", using the common JDBC 2.0
setBinaryStream
/setCharacterStream
method for setting the content. Switch this to "true" for explicit Blob / Clob wrapping against JDBC drivers that are known to require such wrapping (e.g. PostgreSQL's for access to OID columns, whereas BYTEA columns need to be accessed the standard way).This setting affects byte array / String arguments as well as stream arguments, unless
"streamAsLob"
overrides this handling to use JDBC 4.0's new explicit streaming support (if available).
setStreamAsLob
public void setStreamAsLob(boolean streamAsLob)
Specify whether to submit a binary stream / character stream to the JDBC driver as explicit LOB content, using the JDBC 4.0setBlob
/setClob
method with a stream argument.Default is "false", using the common JDBC 2.0
setBinaryStream
/setCharacterStream
method for setting the content. Switch this to "true" for explicit JDBC 4.0 streaming, provided that your JDBC driver actually supports those JDBC 4.0 operations (e.g. Derby's).This setting affects stream arguments as well as byte array / String arguments, requiring JDBC 4.0 support. For supporting LOB content against JDBC 3.0, check out the
"wrapAsLob"
setting.
setCreateTemporaryLob
public void setCreateTemporaryLob(boolean createTemporaryLob)
Specify whether to copy a byte array / String into a temporary JDBC Blob / Clob object created through the JDBC 4.0createBlob
/createClob
methods.Default is "false", using the common JDBC 2.0
setBinaryStream
/setCharacterStream
method for setting the content. Switch this to "true" for explicit Blob / Clob creation using JDBC 4.0.This setting affects stream arguments as well as byte array / String arguments, requiring JDBC 4.0 support. For supporting LOB content against JDBC 3.0, check out the
"wrapAsLob"
setting.
getBlobAsBytes
public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException
从接口复制的说明:LobHandler
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
public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException
从接口复制的说明:LobHandler
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
public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException
从接口复制的说明:LobHandler
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
public InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException
从接口复制的说明:LobHandler
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
public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException
从接口复制的说明:LobHandler
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
public LobCreator getLobCreator()
从接口复制的说明:LobHandler
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()