Java Reference
In-Depth Information
Chapter 14: Using Blobs and Clobs to Manage
Images and Documents
In This Chapter
Traditionally, relational database management systems have been designed around the need to handle
simple traditional data types such as bytes, integers, floats, and Strings. The evolution of computer
hardware and software has introduced both the need and the capability to store much larger data
objects, such as images and even video clips, economically and efficiently.
Until recently, these larger data objects have been stored in traditional file systems, resulting in
significant loss of efficiency whenever very large numbers of such objects were involved. The designers
of relational database management systems have responded by providing support for the management
and storage of these large objects within the database itself.
This chapter discusses the use of relational databases to store and retrieve large objects in various
ways. Examples include the use of servlets to upload images to a database, and to retrieve them for
display in a browser.
Large Objects
Support for large objects (LOBs) is an important feature of modern object relational databases. The
SQL3 standard defines a number of new data types for managing large objects. These data types are
supported by the JDBC extension API. The new SQL3 large object data types supported by the JDBC
2.0 extension include the following:
 
ARRAY — which can store an array as a column value
 
BLOB (binary large object) — which can store large amounts of data as raw bytes
 
CLOB (character large object) — which can store large amounts of character data
 
Structured types
 
References to structured types
Caution
Different RDBMS systems use different internal types to manage large objects, so
refer to your documentation to find out which data types to use for large-object
storage.
JDBC 2.0 defines a set of interfaces that map SQL3 types. Table 14-1 shows the type mappings and
the retrieval, storage, and update methods for the different large object types.
Table 14-1: SQL3 Large Object Data Types
SQL3 type
Java
Interface
get
set
Update
BLOB
java.sql.Blob
getBlob
setBlob
updateBlob
CLOB
java.sql.Clob
getClob
setClob
updateClob
ARRAY
java.sql.Array
getArray
setArray
updateArray
SQL Structured type
java.sql.Struct
getObject
setObject
updateObject
REF to Structured Type
java.sql.Ref
getObject
setObject
updateObject
Note
At the time of this writing, the update methods are scheduled for future release. Until
then, you can use the method updateObject, which works just as well.
Large-object support is the database community's response to evolving requirements to manage
nontraditional data types, such as images, as well as more traditional data types, such as prices, dates,
and quantities. The traditional data types are relatively simple and typically require anywhere from a
handful of bytes for an integer value to perhaps a few tens of bytes for a name or address. Relational
 
Search WWH ::




Custom Search