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), 38 of 41


Closing a BFILE with FILECLOSE

Figure 12-34 Use Case Diagram: Closing a BFILE with FILECLOSE


Text description of adl12b37.gif follows This link takes you back to the External LOBs (BFILES) main diagram.
Text description of the illustration adl12b37.gif

See Also:

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

Purpose

This procedure describes how to close a BFILE with FILECLOSE.

Usage Notes

Not applicable.

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

While you can continue to use the older FILECLOSE form, we strongly recommend that you switch to using CLOSE, because this facilitate future extensibility. This example can be read in conjunction with the example of opening a BFILE.

Examples

PL/SQL (DBMS_LOB Package): Closing a BFile with FILECLOSE

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

C (OCI): Closing a BFile with FILECLOSE

void BfileFileClose(envhp, errhp, svchp, stmthp) 
OCIEnv       *envhp; 
OCIError     *errhp; 
OCISvcCtx    *svchp; 
OCIStmt      *stmthp; 
{ 

   OCILobLocator *bfile_loc; 
 
   /* Allocate the locator descriptors */ 
   (void) OCIDescriptorAlloc((dvoid *) envhp, (dvoid **) &bfile_loc,
                             (ub4) OCI_DTYPE_FILE,  
                             (size_t) 0, (dvoid **) 0);

   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));

   checkerr(errhp, OCILobFileClose(svchp, errhp, bfile_loc));

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

Visual Basic (OO4O): Closing a BFile with FILECLOSE


Note:

At the present time, OO4O only offers BFILE closing with CLOSE (see below). 



Java (JDBC): Closing a BFile with FILECLOSE

import java.io.InputStream;
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_45
{
  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;
       boolean result = false;

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

       result = src_lob.isFileOpen();
       System.out.println(
          "result of fileIsOpen() before opening file : " + result);

       src_lob.openFile();

       result = src_lob.isFileOpen();
       System.out.println(
          "result of fileIsOpen() after opening file : " + result);

       // 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