Objectives
After reading this document, you should be able to:
- Create LOB(Large OBject) objects in a Java program and pass it as a parameter to a database stored procedure.
This document illustrates the same by giving the code snippet and description. - Run the sample using the instructions provided.
Software Requirements
- JDK1.3.x or above This can be downloaded from here.
- Oracle9i Database Release 2 or later. This can be downloaded from here.
- Oracle9i JDBC Driver. This can be downloaded from here.
Note: Oracle JDBC Driver is available with Oracle Database/client installation. If you have a database/client installation,
you need not download JDBC driver separately.
Description
LOBs or Large Objects, are designed to support the unstructured data that cannot be decomposed into standard components i.e they can't be broken down into any finer structure in terms of database storage. LOBs can store unstructured data and is optimized for large amounts of data such as text, graphic images, still video clips, full motion video, and sound waveforms. They provide a uniform way of accessing large unstructured data within the database or outside.
With Oracle 8 and above, there can be multiple LOB columns in a database table, which can also be of different types. The storage capacity of LOBs is upto 4GB.
Oracle supports the following two types of LOBs.
- BLOB, CLOB, and NCLOB: These are stored in the database either in-line in the table or in a separate segment or tablespace.
- BLOBs can store large amounts of binary data typically graphic images and pictures.
- CLOBs can store large amounts of character data and are useful for storing unstructured XML documents.
- NCLOB: consists of character data that corresponds to the national character set defined for the Oracle database.
- BFILEs: These are stored as operating system files.
- BFILE is a LOB whose value is composed of binary ("raw") data, and is stored outside the database tablespaces in a server-side operating system file.
- BFILE is a LOB whose value is composed of binary ("raw") data, and is stored outside the database tablespaces in a server-side operating system file.
Sample Scenario:
Lets assume a story table in the database having two columns, an id and a CLOB. The story text is stored in the CLOB column. A stored procedure updates the story table in the database. It accepts two input parameters: id and CLOB. Below is an example SQL code snippet:
Database preparation:
|
We shall now look into different ways of passing CLOB to a database stored procedure. We can create and manipulate CLOB object in two ways:
With and without streaming the data. Data streaming is always recommended for large amount of data.
Below is the code snippet for both the ways.
Without Streaming the data and using oracle.sql.CLOB class
|
Calling the database procedure by using the above getCLOB method:
|
Creating CLOB object by streaming the data
|
1 comments:
Very good example for CLOB
Thanks , saved my time
Krish
Post a Comment