public class SqlLobValue extends Object implements DisposableSqlTypeValue
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});
LobHandler,
LobCreator,
JdbcTemplate.update(String, Object[], int[]),
SqlUpdate.update(Object[]),
StoredProcedure.execute(java.util.Map)TYPE_UNKNOWN| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cleanup()
Close the LobCreator, if any.
|
void |
setTypeValue(PreparedStatement ps,
int paramIndex,
int sqlType,
String typeName)
Set the specified content via the LobCreator.
|
public SqlLobValue(byte[] bytes)
bytes - the byte array containing the BLOB valueDefaultLobHandlerpublic SqlLobValue(byte[] bytes,
LobHandler lobHandler)
bytes - the byte array containing the BLOB valuelobHandler - the LobHandler to be usedpublic SqlLobValue(String content)
content - the String containing the CLOB valueDefaultLobHandlerpublic SqlLobValue(String content, LobHandler lobHandler)
content - the String containing the CLOB valuelobHandler - the LobHandler to be usedpublic SqlLobValue(InputStream stream, int length)
stream - the stream containing the LOB valuelength - the length of the LOB valueDefaultLobHandlerpublic SqlLobValue(InputStream stream, int length, LobHandler lobHandler)
stream - the stream containing the LOB valuelength - the length of the LOB valuelobHandler - the LobHandler to be usedpublic SqlLobValue(Reader reader, int length)
reader - the character stream containing the CLOB valuelength - the length of the CLOB valueDefaultLobHandlerpublic SqlLobValue(Reader reader, int length, LobHandler lobHandler)
reader - the character stream containing the CLOB valuelength - the length of the CLOB valuelobHandler - the LobHandler to be usedpublic void setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName) throws SQLException
setTypeValue in interface SqlTypeValueps - the PreparedStatement to work onparamIndex - the index of the parameter for which we need to set the valuesqlType - SQL type of the parameter we are settingtypeName - the type name of the parameter (optional)SQLException - if a SQLException is encountered while setting parameter valuesTypes,
PreparedStatement.setObject(int, java.lang.Object, int)public void cleanup()
cleanup in interface DisposableSqlTypeValuecleanup(),
SqlValue.cleanup()