类 SqlLobValue
- java.lang.Object
- org.springframework.jdbc.core.support.SqlLobValue
- 所有已实现的接口:
DisposableSqlTypeValue
,SqlTypeValue
public class SqlLobValue extends Object implements DisposableSqlTypeValue
Object to represent an SQL BLOB/CLOB value parameter. BLOBs can either be an InputStream or a byte array. CLOBs can be in the form of a Reader, InputStream or String. Each CLOB/BLOB value will be stored together with its length. The type is based on which constructor is used. Objects of this class are immutable except for the LobCreator reference. Use them and discard them.This class holds a reference to a LocCreator that must be closed after the update has completed. This is done via a call to the closeLobCreator method. All handling of the LobCreator is done by the framework classes that use it - no need to set or close the LobCreator for end users of this class.
A usage example:
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // reusable object LobHandler lobHandler = new DefaultLobHandler(); // reusable object jdbcTemplate.update( "INSERT INTO imagedb (image_name, content, description) VALUES (?, ?, ?)", new Object[] { name, new SqlLobValue(contentStream, contentLength, lobHandler), new SqlLobValue(description, lobHandler) }, new int[] {Types.VARCHAR, Types.BLOB, Types.CLOB});
- 从以下版本开始:
- 1.1
- 作者:
- Thomas Risberg, Juergen Hoeller
- 另请参阅:
LobHandler
,LobCreator
,JdbcTemplate.update(String, Object[], int[])
,SqlUpdate.update(Object[])
,StoredProcedure.execute(java.util.Map)
字段概要
从接口继承的字段 org.springframework.jdbc.core.SqlTypeValue
TYPE_UNKNOWN
构造器概要
构造器 构造器 说明 SqlLobValue(byte[] bytes)
Create a new BLOB value with the given byte array, using a DefaultLobHandler.SqlLobValue(byte[] bytes, LobHandler lobHandler)
Create a new BLOB value with the given byte array.SqlLobValue(InputStream stream, int length)
Create a new BLOB/CLOB value with the given stream, using a DefaultLobHandler.SqlLobValue(InputStream stream, int length, LobHandler lobHandler)
Create a new BLOB/CLOB value with the given stream.SqlLobValue(Reader reader, int length)
Create a new CLOB value with the given character stream, using a DefaultLobHandler.SqlLobValue(Reader reader, int length, LobHandler lobHandler)
Create a new CLOB value with the given character stream.SqlLobValue(String content)
Create a new CLOB value with the given content string, using a DefaultLobHandler.SqlLobValue(String content, LobHandler lobHandler)
Create a new CLOB value with the given content string.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
cleanup()
Close the LobCreator, if any.void
setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName)
Set the specified content via the LobCreator.
构造器详细资料
SqlLobValue
public SqlLobValue(@Nullable byte[] bytes)
Create a new BLOB value with the given byte array, using a DefaultLobHandler.- 参数:
bytes
- the byte array containing the BLOB value- 另请参阅:
DefaultLobHandler
SqlLobValue
public SqlLobValue(@Nullable byte[] bytes, LobHandler lobHandler)
Create a new BLOB value with the given byte array.- 参数:
bytes
- the byte array containing the BLOB valuelobHandler
- the LobHandler to be used
SqlLobValue
public SqlLobValue(@Nullable String content)
Create a new CLOB value with the given content string, using a DefaultLobHandler.- 参数:
content
- the String containing the CLOB value- 另请参阅:
DefaultLobHandler
SqlLobValue
public SqlLobValue(@Nullable String content, LobHandler lobHandler)
Create a new CLOB value with the given content string.- 参数:
content
- the String containing the CLOB valuelobHandler
- the LobHandler to be used
SqlLobValue
public SqlLobValue(InputStream stream, int length)
Create a new BLOB/CLOB value with the given stream, using a DefaultLobHandler.- 参数:
stream
- the stream containing the LOB valuelength
- the length of the LOB value- 另请参阅:
DefaultLobHandler
SqlLobValue
public SqlLobValue(InputStream stream, int length, LobHandler lobHandler)
Create a new BLOB/CLOB value with the given stream.- 参数:
stream
- the stream containing the LOB valuelength
- the length of the LOB valuelobHandler
- the LobHandler to be used
SqlLobValue
public SqlLobValue(Reader reader, int length)
Create a new CLOB value with the given character stream, using a DefaultLobHandler.- 参数:
reader
- the character stream containing the CLOB valuelength
- the length of the CLOB value- 另请参阅:
DefaultLobHandler
SqlLobValue
public SqlLobValue(Reader reader, int length, LobHandler lobHandler)
Create a new CLOB value with the given character stream.- 参数:
reader
- the character stream containing the CLOB valuelength
- the length of the CLOB valuelobHandler
- the LobHandler to be used
方法详细资料
setTypeValue
public void setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, @Nullable String typeName) throws SQLException
Set the specified content via the LobCreator.- 指定者:
setTypeValue
在接口中SqlTypeValue
- 参数:
ps
- the PreparedStatement to work onparamIndex
- the index of the parameter for which we need to set the valuesqlType
- the SQL type of the parameter we are settingtypeName
- the type name of the parameter (optional)- 抛出:
SQLException
- if an SQLException is encountered while setting parameter values- 另请参阅:
Types
,PreparedStatement.setObject(int, java.lang.Object, int)
cleanup
public void cleanup()
Close the LobCreator, if any.- 指定者:
cleanup
在接口中DisposableSqlTypeValue
- 另请参阅:
cleanup()
,SqlValue.cleanup()