Oracle9i Application Developer's Guide - Large Objects (LOBs)
Release 1 (9.0.1)

Part Number A88879-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to beginning of chapter Go to next page

External LOBs (BFILEs), 17 of 41


Opening a BFILE with FILEOPEN

Figure 12-13 Use Case Diagram: Opening a BFILE with FILEOPEN


Text description of adl12bf7.gif follows This link takes you back to the External LOBs (BFILES) main diagram. This link takes you back to the main (mother) diagram, Opening a BFILE.
Text description of the illustration adl12bf7.gif

See Also:

"Use Case Model: External LOBs (BFILEs)" for all basic operations of External LOBs (BFILES). 

Purpose

This procedure describes how to open a BFILE using FILEOPEN.

Usage Notes

While you can continue to use the older FILEOPEN form, we strongly recommend that you switch to using OPEN, because this facilitates future extensibility.

Syntax

See Chapter 3, "LOB Support in Different Programmatic Environments" for a list of available functions in each programmatic environment. Use the following syntax references for each programmatic environment:

Scenario

These examples open a Lincoln_photo in operating system file PHOTO_DIR. Examples are provided in the following four programmatic environments:

Examples

PL/SQL: Opening a BFILE with FILEOPEN

/* Note that the example procedure openBFILE_procOne is not part of the 
   DBMS_LOB package: */
CREATE OR REPLACE PROCEDURE openBFILE_procOne IS 
   File_loc    BFILE := BFILENAME('PHOTO_DIR', 'Lincoln_photo'); 
BEGIN 
   /* Open the BFILE: */ 
   DBMS_LOB.FILEOPEN (File_loc, DBMS_LOB.FILE_READONLY);
   /* ... Do some processing. */ 
   DBMS_LOB.FILECLOSE(File_loc);
END; 

C (OCI): Opening a BFILE with FILEOPEN

void BfileOpen(envhp, errhp, svchp, stmthp)
OCIEnv  *envhp; 
OCIError *errhp; 
OCISvcCtx *svchp; 
OCIStmt *stmthp; 
{ 
     OCILobLocator *bfile_loc; 
 
     /* Allocate the locator descriptor */ 
     (void) OCIDescriptorAlloc((dvoid *) envhp, (dvoid **) &bfile_loc,  
                               (ub4) OCI_DTYPE_FILE,  
                               (size_t) 0, (dvoid **) 0);
     
     /* Set the bfile locator information */ 
     checkerr(errhp, (OCILobFileSetName(envhp, errhp, &bfile_loc,  
                                        (OraText *)"PHOTO_DIR", 
                                        (ub2)strlen("PHOTO_DIR"),  
                                        (OraText *)"Lincoln_photo",  
                                        (ub2)strlen("Lincoln_photo")))); 
  checkerr(errhp, OCILobFileOpen(svchp, errhp, bfile_loc, 
                                 (ub1)OCI_FILE_READONLY));
  /* ... Do some processing. */
  checkerr(errhp, OCILobFileClose(svchp, errhp, bfile_loc));

  /* Free the locator descriptor */ 
  OCIDescriptorFree((dvoid *)bfile_loc, (ub4)OCI_DTYPE_FILE); 
} 

Visual Basic (OO4O): Opening a BFILE with FILEOPEN


Note:

At the present time, OO4O only offers BFILE opening with OPEN (see "Visual Basic (OO4O) Opening a BFILE with OPEN"). 


Java (JDBC): Opening a BFILE with FILEOPEN

import java.io.OutputStream;
// Core JDBC classes: 
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

// Oracle Specific JDBC classes: 
import oracle.sql.*;
import oracle.jdbc.driver.*;

public class Ex4_38
{

  public static void main (String args [])
       throws Exception
  {
    // Load the Oracle JDBC driver: 
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    // Connect to the database: 
    Connection conn =
      DriverManager.getConnection ("jdbc:oracle:oci8:@", "samp", "samp");

    conn.setAutoCommit (false);

    // Create a Statement: 
    Statement stmt = conn.createStatement ();
    try
    {
       BFILE src_lob = null;
       ResultSet rset = null;

       rset = stmt.executeQuery (
       "SELECT BFILENAME('PHOTO_DIR', 'Lincoln_photo') FROM DUAL");
       if (rset.next())
       {
           src_lob = ((OracleResultSet)rset).getBFILE (1);

           src_lob.openFile();
          System.out.println("The file is now open");
        }

        // Close the BFILE, statement and connection: 
        src_lob.closeFile();
        stmt.close();
        conn.commit();
        conn.close();
    }
    catch (SQLException e)
    {
        e.printStackTrace();
    }
  }
}


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback