Top Description Fields Constructors Methods
org.springframework.jdbc.core.support

public Class SqlLobValue

extends Object
implements DisposableSqlTypeValue
Class Inheritance
All Implemented Interfaces
org.springframework.jdbc.core.DisposableSqlTypeValue, org.springframework.jdbc.core.SqlTypeValue
Imports
java.io.InputStream, .Reader, java.sql.PreparedStatement, .SQLException, .Types, org.springframework.jdbc.core.DisposableSqlTypeValue, org.springframework.jdbc.support.lob.DefaultLobHandler, .LobCreator, .LobHandler, org.springframework.lang.Nullable

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. Instances of this class are stateful and immutable: use them and discard them.

NOTE: As of 6.1.4, this class is effectively superseded by SqlBinaryValue and SqlCharacterValue which are capable of modern BLOB/CLOB handling while also handling LONGVARBINARY/LONGVARCHAR. The only reason to keep using this class is a custom LobHandler.

This class holds a reference to a LobCreator that must be closed after the update has completed. This is done via a call to the cleanup() 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});
Authors
Thomas Risberg, Juergen Hoeller
Since
1.1
See Also
org.springframework.jdbc.support.lob.LobHandler, org.springframework.jdbc.support.lob.LobCreator, org.springframework.jdbc.core.JdbcTemplate#update(String, Object[], int[]), org.springframework.jdbc.object.SqlUpdate#update(Object[]), org.springframework.jdbc.object.StoredProcedure#execute(java.util.Map)

Field Summary

Modifier and TypeField and Description
private final Object
private final int
private final LobCreator
lobCreator

Reference to the LobCreator - so we can close it once the update is done.

Constructor Summary

AccessConstructor and Description
public
SqlLobValue(byte[]
the byte array containing the BLOB value
bytes
)

Create a new BLOB value with the given byte array, using a DefaultLobHandler.

public
SqlLobValue(byte[]
the byte array containing the BLOB value
bytes
,
LobHandler
the LobHandler to be used
lobHandler
)

Create a new BLOB value with the given byte array.

public
SqlLobValue(String
the String containing the CLOB value
content
)

Create a new CLOB value with the given content string, using a DefaultLobHandler.

public
SqlLobValue(String
the String containing the CLOB value
content
,
LobHandler
the LobHandler to be used
lobHandler
)

Create a new CLOB value with the given content string.

public
SqlLobValue(InputStream
the stream containing the LOB value
stream
,
int
the length of the LOB value
length
)

Create a new BLOB/CLOB value with the given stream, using a DefaultLobHandler.

public
SqlLobValue(InputStream
the stream containing the LOB value
stream
,
int
the length of the LOB value
length
,
LobHandler
the LobHandler to be used
lobHandler
)

Create a new BLOB/CLOB value with the given stream.

public
SqlLobValue(Reader
the character stream containing the CLOB value
reader
,
int
the length of the CLOB value
length
)

Create a new CLOB value with the given character stream, using a DefaultLobHandler.

public
SqlLobValue(Reader
the character stream containing the CLOB value
reader
,
int
the length of the CLOB value
length
,
LobHandler
the LobHandler to be used
lobHandler
)

Create a new CLOB value with the given character stream.

Method Summary

Modifier and TypeMethod and Description
public void
public void
setTypeValue(PreparedStatement
the PreparedStatement to work on
ps
,
int
the index of the parameter for which we need to set the value
paramIndex
,
int
the SQL type of the parameter we are setting
sqlType
,
String
the type name of the parameter (optional)
typeName
)

Implements org.springframework.jdbc.core.SqlTypeValue.setTypeValue.

Set the specified content via the LobCreator.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentback to summary
private final Object content
Annotations
@Nullable
lengthback to summary
private final int length
lobCreatorback to summary
private final LobCreator lobCreator

Reference to the LobCreator - so we can close it once the update is done.

Constructor Detail

SqlLobValueback to summary
public SqlLobValue(byte[] bytes)

Create a new BLOB value with the given byte array, using a DefaultLobHandler.

Parameters
bytes:byte[]

the byte array containing the BLOB value

See Also
org.springframework.jdbc.support.lob.DefaultLobHandler
SqlLobValueback to summary
public SqlLobValue(byte[] bytes, LobHandler lobHandler)

Create a new BLOB value with the given byte array.

Parameters
bytes:byte[]

the byte array containing the BLOB value

lobHandler:LobHandler

the LobHandler to be used

SqlLobValueback to summary
public SqlLobValue(String content)

Create a new CLOB value with the given content string, using a DefaultLobHandler.

Parameters
content:String

the String containing the CLOB value

See Also
org.springframework.jdbc.support.lob.DefaultLobHandler
SqlLobValueback to summary
public SqlLobValue(String content, LobHandler lobHandler)

Create a new CLOB value with the given content string.

Parameters
content:String

the String containing the CLOB value

lobHandler:LobHandler

the LobHandler to be used

SqlLobValueback to summary
public SqlLobValue(InputStream stream, int length)

Create a new BLOB/CLOB value with the given stream, using a DefaultLobHandler.

Parameters
stream:InputStream

the stream containing the LOB value

length:int

the length of the LOB value

See Also
org.springframework.jdbc.support.lob.DefaultLobHandler
SqlLobValueback to summary
public SqlLobValue(InputStream stream, int length, LobHandler lobHandler)

Create a new BLOB/CLOB value with the given stream.

Parameters
stream:InputStream

the stream containing the LOB value

length:int

the length of the LOB value

lobHandler:LobHandler

the LobHandler to be used

SqlLobValueback to summary
public SqlLobValue(Reader reader, int length)

Create a new CLOB value with the given character stream, using a DefaultLobHandler.

Parameters
reader:Reader

the character stream containing the CLOB value

length:int

the length of the CLOB value

See Also
org.springframework.jdbc.support.lob.DefaultLobHandler
SqlLobValueback to summary
public SqlLobValue(Reader reader, int length, LobHandler lobHandler)

Create a new CLOB value with the given character stream.

Parameters
reader:Reader

the character stream containing the CLOB value

length:int

the length of the CLOB value

lobHandler:LobHandler

the LobHandler to be used

Method Detail

cleanupback to summary
public void cleanup()

Implements org.springframework.jdbc.core.DisposableSqlTypeValue.cleanup.

Close the LobCreator.

Annotations
@Override
setTypeValueback to summary
public void setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName) throws SQLException

Implements org.springframework.jdbc.core.SqlTypeValue.setTypeValue.

Set the specified content via the LobCreator.

Parameters
ps:PreparedStatement

Doc from org.springframework.jdbc.core.SqlTypeValue.setTypeValue.

the PreparedStatement to work on

paramIndex:int

Doc from org.springframework.jdbc.core.SqlTypeValue.setTypeValue.

the index of the parameter for which we need to set the value

sqlType:int

Doc from org.springframework.jdbc.core.SqlTypeValue.setTypeValue.

the SQL type of the parameter we are setting

typeName:String

Doc from org.springframework.jdbc.core.SqlTypeValue.setTypeValue.

the type name of the parameter (optional)

Annotations
@Override
Exceptions
SQLException:

Doc from org.springframework.jdbc.core.SqlTypeValue.setTypeValue.

if an SQLException is encountered while setting parameter values