Oracle8i Application Developer's Guide - Large Objects (LOBs) Release 2 (8.1.6) Part Number A76940-01 |
|
External LOBs (BFILEs), 17 of 41
See Also:
"Use Case Model: External LOBs (BFILEs)" for all basic operations of External LOBs (BFILES). |
This procedure describes how to open a BFILE using FILEOPEN
.
While you can continue to use the older FILEOPEN
form, we strongly recommend that you switch to using OPEN
, because this facilitates future extensibility.
See Chapter 3, "LOB Programmatic Environments" for a list of available functions in each programmatic environment. Use the following syntax references for each programmatic environment:
These examples open a Lincoln_photo
in operating system file PHOTO_DIR
. Examples are provided in the following four programmatic environments:
/* Note that the example procedure openBFILE_procOne is not part of the DBMS_LOB package: */ CREATE OR REPLACE PROCEDURE openBFILE_procOne IS Lob_loc BFILE := BFILENAME('PHOTO_DIR', 'Lincoln_photo'); BEGIN /* Open the BFILE: */ DBMS_LOB.FILEOPEN (Lob_loc, DBMS_LOB.FILE_READONLY); /* ... Do some processing. */ DBMS_LOB.FILECLOSE(Lob_loc); END;
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); }
Note:
At the present time, OO4O only offers |
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(); } } }
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|