Class SqlBinaryValue
- All Implemented Interfaces:
SqlTypeValue
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.
Note: Only specify Types.BLOB in case of an actual BLOB, preferring
Types.LONGVARBINARY otherwise. With PostgreSQL, Types.ARRAY
has to be specified for BYTEA columns, rather than Types.BLOB. This
is in contrast to SqlLobValue where byte array handling was lenient.
- Since:
- 6.1.4
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from interface SqlTypeValue
TYPE_UNKNOWN -
Constructor Summary
ConstructorsConstructorDescriptionSqlBinaryValue(byte[] bytes) Create a newSqlBinaryValuefor the given content.SqlBinaryValue(InputStream stream, long length) Create a newSqlBinaryValuefor the given content.SqlBinaryValue(InputStreamSource resource, long length) Create a newSqlBinaryValuefor the given content.SqlBinaryValue(Resource resource) Create a newSqlBinaryValuefor the given content. -
Method Summary
Modifier and TypeMethodDescriptionvoidsetTypeValue(PreparedStatement ps, int paramIndex, int sqlType, @Nullable String typeName) Set the type value on the given PreparedStatement.
-
Constructor Details
-
SqlBinaryValue
public SqlBinaryValue(byte[] bytes) Create a newSqlBinaryValuefor the given content.- Parameters:
bytes- the content as a byte array
-
SqlBinaryValue
Create a newSqlBinaryValuefor the given content.- Parameters:
stream- the content streamlength- the length of the content
-
SqlBinaryValue
Create a newSqlBinaryValuefor the given content.Consider specifying a
Resourcewith 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 newSqlBinaryValuefor 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:SqlTypeValueSet the type value on the given PreparedStatement.- Specified by:
setTypeValuein 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:
-