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

public Class SqlBinaryValue

extends Object
implements SqlTypeValue
Class Inheritance
All Implemented Interfaces
org.springframework.jdbc.core.SqlTypeValue
Imports
java.io.ByteArrayInputStream, .IOException, .InputStream, java.sql.PreparedStatement, .SQLException, .Types, org.springframework.core.io.InputStreamSource, .Resource, org.springframework.jdbc.core.SqlTypeValue, org.springframework.lang.Nullable

Object to represent a binary parameter value for a SQL statement, e.g. a binary stream for a BLOB or a LONGVARBINARY or PostgreSQL BYTEA column.

Designed for use with org.springframework.jdbc.core.JdbcTemplate as well as org.springframework.jdbc.core.simple.JdbcClient, to be passed in as a parameter value wrapping the target content value. Can be combined with org.springframework.jdbc.core.SqlParameterValue for specifying a SQL type, e.g. new SqlParameterValue(Types.BLOB, new SqlBinaryValue(myContent)). With most database drivers, the type hint is not actually necessary.

Author
Juergen Hoeller
Since
6.1.4
See Also
SqlCharacterValue, org.springframework.jdbc.core.SqlParameterValue

Field Summary

Modifier and TypeField and Description
private final Object
private final long

Constructor Summary

AccessConstructor and Description
public
SqlBinaryValue(byte[]
the content as a byte array
bytes
)

Create a new SqlBinaryValue for the given content.

public
SqlBinaryValue(InputStream
the content stream
stream
,
long
the length of the content
length
)

Create a new SqlBinaryValue for the given content.

public
SqlBinaryValue(InputStreamSource
the resource to obtain a content stream from
resource
,
long
the length of the content
length
)

Create a new SqlBinaryValue for the given content.

public
SqlBinaryValue(Resource
the resource to obtain a content stream from
resource
)

Create a new SqlBinaryValue for the given content.

Method Summary

Modifier and TypeMethod and Description
private void
setByteArray(PreparedStatement ps, int paramIndex, int sqlType, byte[] bytes)

private void
setInputStream(PreparedStatement ps, int paramIndex, int sqlType, InputStream is, long length)

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 type value on the given PreparedStatement.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentback to summary
private final Object content
lengthback to summary
private final long length

Constructor Detail

SqlBinaryValueback to summary
public SqlBinaryValue(byte[] bytes)

Create a new SqlBinaryValue for the given content.

Parameters
bytes:byte[]

the content as a byte array

SqlBinaryValueback to summary
public SqlBinaryValue(InputStream stream, long length)

Create a new SqlBinaryValue for the given content.

Parameters
stream:InputStream

the content stream

length:long

the length of the content

SqlBinaryValueback to summary
public SqlBinaryValue(InputStreamSource resource, long length)

Create a new SqlBinaryValue for the given content.

Consider specifying a Resource with content length support when available: SqlBinaryValue#SqlBinaryValue(Resource).

Parameters
resource:InputStreamSource

the resource to obtain a content stream from

length:long

the length of the content

SqlBinaryValueback to summary
public SqlBinaryValue(Resource resource)

Create a new SqlBinaryValue for the given content.

The length will get derived from Resource#contentLength().

Parameters
resource:Resource

the resource to obtain a content stream from

Method Detail

setByteArrayback to summary
private void setByteArray(PreparedStatement ps, int paramIndex, int sqlType, byte[] bytes) throws SQLException
setInputStreamback to summary
private void setInputStream(PreparedStatement ps, int paramIndex, int sqlType, InputStream is, long length) throws SQLException
setTypeValueback to summary
public void setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName) throws SQLException

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

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

Set the type value on the given PreparedStatement.

Parameters
ps:PreparedStatement

the PreparedStatement to work on

paramIndex:int

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

sqlType:int

the SQL type of the parameter we are setting

typeName:String

the type name of the parameter (optional)

Annotations
@Override
Exceptions
SQLException:
if an SQLException is encountered while setting parameter values