Package org.springframework.jdbc.core.support

# Class SqlBinaryValue

java.lang.Object
org.springframework.jdbc.core.support.SqlBinaryValue

All Implemented Interfaces:
  `SqlTypeValue`

public class SqlBinaryValue extends Object implements SqlTypeValue
Object to represent a binary parameter value for an 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 an 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:
  - `SqlCharacterValue`
  - `SqlParameterValue`

## Field Summary

### Fields inherited from interface org.springframework.jdbc.core.SqlTypeValue

`TYPE_UNKNOWN`

## Constructor Summary

Constructors
Constructor
Description
`SqlBinaryValue(byte[] bytes)`
Create a new `SqlBinaryValue` for the given content.
`SqlBinaryValue(InputStream stream, long length)`
Create a new `SqlBinaryValue` for the given content.
`SqlBinaryValue(org.springframework.core.io.InputStreamSource resource, long length)`
Create a new `SqlBinaryValue` for the given content.
`SqlBinaryValue(org.springframework.core.io.Resource resource)`
Create a new `SqlBinaryValue` for the given content.

## Method Summary

Modifier and Type
Method
Description
`void`
`setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName)`
Set the type value on the given PreparedStatement.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### SqlBinaryValue

public SqlBinaryValue(byte[] bytes)
Create a new `SqlBinaryValue` for the given content.

Parameters:
  `bytes` - the content as a byte array

### SqlBinaryValue

public SqlBinaryValue(InputStream stream, long length)
Create a new `SqlBinaryValue` for the given content.

Parameters:
  `stream` - the content stream
  `length` - the length of the content (or -1 if undetermined)

### SqlBinaryValue

public SqlBinaryValue(org.springframework.core.io.InputStreamSource resource, long length)
Create a new `SqlBinaryValue` 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 from
  `length` - the length of the content (or -1 if undetermined)

### SqlBinaryValue

public SqlBinaryValue(org.springframework.core.io.Resource resource)
Create a new `SqlBinaryValue` 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 interface `SqlTypeValue`
Parameters:
  `ps` - the PreparedStatement to work on
  `paramIndex` - the index of the parameter for which we need to set the value
  `sqlType` - the SQL type of the parameter we are setting
  `typeName` - the type name of the parameter (optional)
Throws:
  `SQLException` - if an SQLException is encountered while setting parameter values
See Also:
  - `Types`
  - `PreparedStatement.setObject(int, java.lang.Object, int)`