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 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.

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:
  • 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
    • SqlBinaryValue

      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(Resource).

      Parameters:
      resource - the resource to obtain a content stream from
      length - the length of the content
    • SqlBinaryValue

      public SqlBinaryValue(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