Class SqlBinaryValue
java.lang.Object
org.springframework.jdbc.core.support.SqlBinaryValue
- All Implemented Interfaces:
SqlTypeValue
Object to represent a binary parameter value for a SQL statement, for example,
a binary stream for a BLOB or a LONGVARBINARY or PostgreSQL BYTEA column.
Designed for use with JdbcTemplate
as well as JdbcClient
, to be
passed in as a parameter value wrapping the target content value. Can be
combined with SqlParameterValue
for
specifying a SQL type, for example,
new SqlParameterValue(Types.BLOB, new SqlBinaryValue(myContent))
.
With most database drivers, the type hint is not actually necessary.
- Since:
- 6.1.4
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.jdbc.core.SqlTypeValue
TYPE_UNKNOWN
-
Constructor Summary
ConstructorDescriptionSqlBinaryValue
(byte[] bytes) Create a newSqlBinaryValue
for the given content.SqlBinaryValue
(InputStream stream, long length) Create a newSqlBinaryValue
for the given content.SqlBinaryValue
(InputStreamSource resource, long length) Create a newSqlBinaryValue
for the given content.SqlBinaryValue
(Resource resource) Create a newSqlBinaryValue
for the given content. -
Method Summary
Modifier and TypeMethodDescriptionvoid
setTypeValue
(PreparedStatement ps, int paramIndex, int sqlType, String typeName) Set the type value on the given PreparedStatement.
-
Constructor Details
-
SqlBinaryValue
public SqlBinaryValue(byte[] bytes) Create a newSqlBinaryValue
for the given content.- Parameters:
bytes
- the content as a byte array
-
SqlBinaryValue
Create a newSqlBinaryValue
for the given content.- Parameters:
stream
- the content streamlength
- the length of the content
-
SqlBinaryValue
Create a newSqlBinaryValue
for the given content.Consider specifying a
Resource
with content length support when available:SqlBinaryValue(Resource)
.- Parameters:
resource
- the resource to obtain a content stream fromlength
- the length of the content
-
SqlBinaryValue
Create a newSqlBinaryValue
for the given content.The length will get derived from
Resource.contentLength()
.- Parameters:
resource
- the resource to obtain a content stream from
-
-
Method Details
-
setTypeValue
public void setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, @Nullable String typeName) throws SQLException Description copied from interface:SqlTypeValue
Set the type value on the given PreparedStatement.- Specified by:
setTypeValue
in interfaceSqlTypeValue
- Parameters:
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)- Throws:
SQLException
- if an SQLException is encountered while setting parameter values- See Also:
-