Write code that uses BLOBs

There are a number of tasks that can be accomplished with database Binary Large Object (BLOB) columns through the Java™ Database Connectivity (JDBC) Application Programming Interface (API). The following topics briefly discuss these tasks and include examples on how to accomplish them.

Read BLOBs from the database and insert BLOBs into the database

With the JDBC API, there are ways to get BLOBs out of the database and ways to put BLOBs into the database. However, there is no standardized way to create a Blob object. This is not a problem if your database is already full of BLOBs, but it poses a problem if you want to work with BLOBs from scratch through JDBC. Instead of defining a constructor for the Blob and Clob interfaces of the JDBC API, support is provided for placing BLOBs into the database and getting them out of the database directly as other types. For example, the setBinaryStream method can work with a database column of type Blob. Example: BLOB shows some of the common ways that a BLOB can be put into the database or retrieved from the database.

Work with the Blob object API

BLOBs are defined in JDBC as an interface of which the various drivers provide implementations. This interface has a series of methods that can be used to interact with the Blob object. Example: Use BLOBs shows some of the common tasks that can be performed using this API. Consult the JDBC Javadoc for a complete list of available methods on the Blob object.

Use JDBC 3.0 support to update BLOBs

In JDBC 3.0, there is support for making changes to LOB objects. These changes can be stored into BLOB columns in the database. Example: Update BLOBs shows some of the tasks that can be performed with BLOB support in JDBC 3.0.

Related concepts
Write code that uses CLOBs
Write code that uses Datalinks
Related reference
Example: Distinct types