|
![]() |
![]() |
![]() |
![]() |
![]() |
Leveraging Oracle8 LOBs with Java and JDBCBy Samir Shah
Build an enterprise-class, scaleable multimedia web-enabled database that includes unstructured data, such as photographs, document files, video clips, and sound files, using JDBC and Oracle8's LOB data types.
Toolset: Oracle 8.0.4 for Windows NT Server, Oracle Application Server 4.0 for Windows NT Server,
and Oracle JDeveloper 1.x There's Something about Large Objects (LOBs)Relational databases have been used for over two decades to store garden-variety business information -- the text strings and numeric values that make up an accountholder's name, address, and account balance, for example. Such so-called "structured" information is at the heart of most business systems. With the advent of graphical user interfaces, the Internet and the Web, and an ever-increasing range of multimedia formats, "information" now includes rich, unstructured data types -- everything from graphic images, such as photographs, to audio and video, including sound clips and movies. These data types must also be combined with, or related to, the traditional data elements in today's modern business applications.For example, a law firm might want to manage its caseload by creating a database system to hold all depositions, whether in text, audio, or video format. If the law firm specializes in personal-injury cases, the database might also need to include X rays or other data from medical-imaging systems. This application would require the ability to load, store, and access all the multimedia data in addition to the structured relational data (docket number, case number, attorney name, client name, physicians' names, and so forth). Other potential solutions for today's Internet developer include media-asset-management web sites, where customers can review and approve print ads, television commercials, or radio spots; or an Internet mall that includes product photos, installation demos, and other useful customer-service functions. In the past, creating such applications typically required implementing a special-purpose database for the multimedia data types, in addition to the relational database. And that means the programming logic had to include lots of code for plumbing issues, such as keeping the databases synchronized and maintaining integrity across all data stores in case of a failure. However, because Oracle8 supports large objects (LOBs), you can now create solutions that support multimedia file types much more transparently and easily. And it's not just sophisticated applications that can benefit from integrating rich, unstructured data types with structured data. For example, even a simple employee tracking application, such as that described in this article, can include photographs of employees just as easily as it includes information such as name, salary, and job title. Things Go Better with JavaThis article provides an introduction to Oracle8's support for LOBs using Java and the Java Database Connectivity API, JDBC. JDBC is an object-oriented application programming interface that provides access to relational data. Using JDBC, Java applications and applets can execute SQL statements and stored procedures. There are several advantages to developing applications in Java and JDBC. Chief among them is that Java is portable and is a natural fit for Web deployment. That means you also get all the benefits of the Web, including easy deployment, portability, and easy-to-use applications. In this article, you'll learn how to store, retrieve, and manipulate unstructured information -- in this case, digital photographs of employees -- as LOBs in the Oracle8 database using Java and JDBC. The example application detailed in Listing 1 is an Employee Tracking system that will be deployed in a three-tier architecture over a corporate intranet, specifically implemented using the Oracle Application Server and its JWeb cartridge for the middle tier.In addition to displaying such information as name, job title, hire date, and salary, the Employee Tracking application also displays the employee's photograph, which is as a BFILE data type (one of the four LOB data types in the Oracle8 database -- more in a minute). The application also enables dynamically adding or changing the employee image in the database by choosing an image from the file system.
![]() ![]() This last aspect is key: Although many multi-media solutions can accomplish these things in batch mode, it is this application's ability to dynamically update the large binary data that really highlights the benefits of LOBs, Java, and JDBC. Accessing information in a database from Java requires the use of a JDBC driver from the database vendor. Oracle provides several different drivers, but only Oracle's OCI8 JDBC driver currently supports LOBS. (See the "Introduction to JDBC (Java Database Connectivity)" for additional information on Oracle's JDBC drivers and JDBC in general.) Much of the code for this application was generated by Oracle's JDeveloper, an integrated application development environment that provides many Wizards to speed the development process. (See "Your First JDeveloper Project" for a tutorial on getting started with Java, JDBC, and JDeveloper.) The Skinny on LOBsPrior to Oracle8, unstructured binary information of up to 2 gigabytes could be stored using the LONG RAW data type. However, only one LONG RAW (or RAW, for long character data) column may be defined per table.With Oracle8, your application can access pieces of the LOB, rather than the entire LOB at once. A LOB can be loaded, accessed, and manipulated with PL/SQL statements, by use of the DBMS_LOB package, or with OCI routines. (You'll see that the example Java application in Listing 1 uses a combination of the DBMS_LOB package, stored procedures, and SQL via Oracle's JDBC OCI8 driver for Oracle8. If you haven't done so already, download the Listing to step through the code as you continue reading this article.) As of Oracle8, a database table can include more than one column for LOB data (the LOB data can be up to 4-gigabytes in size) and in one of four different LOB data types. Where a specific LOB file is stored -- internally, in the database, or externally, outside the database -- depends on the specific type of LOB. In addition, within any given table, certain types of LOBs can be stored in-line or out-of-line, depending upon the size of the data.
|