Illustrating use of BFiles


This document is organized into following sub-sections :

  1. Overview of the Sample Application
  2. Required Software
  3. Installation and Configuration
  4. Description of Sample Files

Overview of the Sample Application

This Sample illustrates accessing of BFiles using JDBC. The sample uses the JDBC-Thin driver; the code is the same for JDBC-OCI,
except for the database URL syntax.

Steps in the Sample

  1. The user invokes the application, and the application displays the connection status in the status bar. If the connection was successful, it first drops the table BFILE_TABLE if it already exists. Then it creates a new table BFILE_TABLE(BFILE_COLUMN BFILE).
  2. After creating the table, the application prompts the user to Enter Full Directory Path of the image file (architect.gif). When the user enters the correct path, it inserts a single row comprising of the image file 'architect.gif' into the table. Note that 'architect.gif' file is provided along with the sample.
  3. After insertion of BFile Data, user can press "SELECT" to view the image in the panel.
  4. After user presses "SELECT" button, following steps are executed:
    • BFile Locator is selected from the table BFILE_TABLE
    • Binary Stream is opened on the selected BFILE locator
    • Image Data (Binary Data) is fetched
    • Image is displayed.
  5. When the user presses"EXIT" button, the application exits.

Required Software

  • Oracle9i JDeveloper or higher ( Note: JDeveloper is Oracle's Visual Java Development Tool and can be downloaded from here )
    or

    JDK1.2.x or above (can be downloaded from here )
  • Oracle9i (Database) or higher running SQL*Net TCP/IP listener. This can be downloaded from here.

Installation and Configuration

The section has step-by-step instructions to run this application successfully. This will be discussed in the following subsections

Install the sample

Database Setup

Run the sample using Oracle9i JDeveloper

Run the sample using the JDK environment

Install the sample

Step 1. Unjar BFileSample.jar using Winzip, or using the following command:

> jar xvf BFileSample.jar

You will find jar.exe in JDK_HOME\bin. Ensure that JDK_HOME\bin is in your system path. (JDK_HOME is the root directory of the JDKx.x installation ).

This creates a folder BFileSample with all the source files

Step 2. Go to BFileSample Directory. You will find the image file 'architect.gif'. You need to ftp/copy this .gif file on to the Server where Database is mounted. Please note the complete path of the directory where you have copied this image file. This is the directory that you will specify when the application prompts for the full path to the image on the database server.

Step 3. Edit Connection.properties file located in the directory BFileSample\src. Change the following attributes to those of the database instance you want to connect to.

Change the following lines:

HostName = insn104a.idc.oracle.com
SID = otn9i
Port = 1521
UserName = scott
Password = tiger

Database Setup

Ensure that the database user you are using for this samples has CREATE ANY DIRECTORY system privileges.

This can be done by running the following command at the SQL prompt after connecting as system/<password>

SQL> GRANT CREATE ANY DIRECTORY TO <database-username>;

Run the sample using Oracle9i JDeveloper

Step 1. Using JDeveloper File/Open option select the BFileSample.jws from the BFileSample directory.

Step 2. Select Project/Make from JDeveloper main menu and select Make Project "BFileSample.jpr"

Step 3. Select Run/Run BFileSample.jpr from JDeveloper main menu to run the application.

Run the sample using the JDK Environment

 Step 1. Install Oracle JDBC Driver and include the zip/jar files in the CLASSPATH
              Alos ensure that BFileSample\src directory is added to the CLASSPATH

 Step 2.  Change directory to BFileSample\src\oracle\otnsamples\jdbc\bfile. Compile the files using javac:

               %javac *.java

 Step 3. Run the class file using java from BFileSample directory:            
            
              %java oracle.otnsamples.jdbc.bfile.BFileSample

Description of Sample Files

The directory structure of the deliverable BFileSample.jar will be as shown below

BFileSample is the top level directory.

Directory
Files
Description
BFileSample Readme.html This file
BFileSample.jws The Oracle9i JDeveloper workspace file
BFileSample.jpr The Oracle9i JDeveloper project file
architect.gif Image file which is stored as BFILE Column
BFileSample\src Connection.properties This file has the details of the database connection parameters
BFileSample\src\oracle\otnsamples\jdbc\bfile BFileSample.java The source file for sample
BFileFrame.java The source file for the sample User Interface

 



Please enter your comments about this sample in the OTN Sample Code Discussion Forum.